How to remove unwanted spaces at the right of CheckBox?

checkbox remove padding
checkbox text space
androidx checkbox
set space between checkbox and text
android radio button remove padding
circular checkbox android
custom checkbox android
single checkbox android

I am working on a custom list view. I want to show a CheckBox at the custom view. There is no text for the CheckBox. I found it always have some spaces at the right of the CheckBox.

Here is my layout xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:background="#fa9654"
android:paddingTop="65dp" android:paddingBottom="65dp">



<TextView android:id="@+id/bus_route_list_item_num"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="center" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight="0.15"></TextView>

<TextView android:id="@+id/bus_route_list_item_station"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="left" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight=".5"></TextView>


<TextView android:id="@+id/bus_route_list_item_fee"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="center" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight=".15"></TextView>


<CheckBox android:id="@+id/bus_route_list_item_reminder" android:layout_height="wrap_content" 
    android:layout_width="0dip" android:layout_weight=".20" android:gravity="center" 
    android:layout_gravity="center" android:paddingRight="0dp" android:paddingLeft="0dp" 
    android:paddingTop="0dp" android:paddingBottom="0dp" android:background="#0066ff" 
    android:text=""
/>

</LinearLayout>

The result looks like: http://pwong.name/checkbox_problem2.jpg

As you can see there are some space at the right of the checkbox. What I want is put the checkbox at the middle of the blue area.

Is it possible to remove the unwanted space? thanks

You can wrap CheckBox in LinearLayout and then use android:gravity="center" on that layout.

 <LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="0dip" 
    android:layout_weight=".20"              
    android:background="#ff0000" 
    android:gravity="center">

    <CheckBox android:id="@+id/bus_route_list_item_reminder" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"                     
    />

</LinearLayout>

As another alternative, you can use RelativeLayout. This would greatly simplify you layout and you will be able to get rid of layout_weight.

Removing padding around [input type=checkbox], You can wrap CheckBox in LinearLayout and then use android:gravity="center" on that layout. <LinearLayout  Right click on the column and select Replace Values from the menu. Like the find and replace method, we will need to add two spaces as the Value To Find and a single space as the Replace With value. We can then press the OK button to add this transformation. We need to repeat this step until all the extra spaces have been removed from our data.

Neither of previous solutions worked for me, but I've tried applying a translation to the content and it worked pretty well, no need in additional layout hierarchy, nor implementing own views:

                <CheckBox
                ...
                android:text="@null"
                android:translationX="12dp" />

Also, it keeps bounds of the element in proper place, so touch area is not shifted.

PCs: The Missing Manual, Could anyone advise on how to remove padding around checkbox in IE? but rather the blank space around checkbox (which IE considers to be part of the Which is why it is extra important to use the LABEL element type  Simple commands to remove unwanted whitespace Edit In a search, \s finds whitespace (a space or a tab), and \+ finds one or more occurrences. The following command deletes any trailing whitespace at the end of each line. If no trailing whitespace is found no change occurs, and the e flag means no error is displayed.

To remove extra space at right of the image (when there is no text) extend CheckBox class and override getSuggestedMinimumWidth() method in order to return there image width. Complete solution:

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.CheckBox;

public class CheckBoxWithoutText extends CheckBox
{
    private Drawable buttonDrawable;

    public CheckBoxWithoutText(Context context)
    {
        super(context);
    }

    public CheckBoxWithoutText(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    @Override
    protected int getSuggestedMinimumWidth()
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        {
            return getCompoundPaddingLeft() + getCompoundPaddingRight();
        }
        else
        {
            return buttonDrawable == null ? 0 : buttonDrawable.getIntrinsicWidth();
        }
    }

    @Override
    public void setButtonDrawable(Drawable d)
    {
        buttonDrawable = d;
        super.setButtonDrawable(d);
    }
}

Programming in Visual Basic 2010: The Very Beginner's Guide, Removing Unused Programs and Files PCs: The Missing Manual, eMatter Edition Turning on this checkbox is typically the best way to free up space, but it also To do so, right-click the Recycle Bin, choose Properties, and then slide the bar  The LTRIM removes spaces from the left of the string. The RTRIM removes the spaces from the right of the string. From SQL Server 2017, the TRIM function is also available that removes the space character (char(32)) or other specified string from both sides of the string.

The translationX seems to work. But it causes problem if you want to support RTL layouts. Another solution would be to set the width of checkbox to a fixed length (e.g. 26dp):

<CheckBox
    android:layout_width="26dp"
    android:layout_height="wrap_content"
    android:text="@null" />

Remove trailing space from form element labels and field labels , Trim, TrimStart, and TrimEnd are used to remove spaces in a string. The Like method is used to match patterns of characters in a string. A MaskedTextBox  To Remove Trailing Spaces in Character Field We Can Use SHIFT ----RIGHT---DATA V_CURR(20) VALUE ' Test string to check shift ', length TYPE I. SHIFT V_CURR RIGHT DELETING TRAILING SPACE. WRITE 'String RIGHT :',V_CURR. Output: String LEFT : Test string to check shift. Note SHIFT V_CURR LEFT DELETING LEADING SPACE.

I would use a relative layout here. Aligning checkbox on parent right...

Regards, Stéphane

Photoshop Elements 8 for Mac: The Missing Manual, Problem/Motivation All forms Labels text contain a trailing SPACE. Decide if we want to keep spaces between checkboxes and radio button and their labels, and the space inside Now, it might lose one space at right side. The trimws() function will remove leading or trailing spaces in a string. For example, here is a string with an extra space at the beginning and the end: sentenceString <- ' Dan is here.

Digital Media Tools, To add a border to your photo, turn on the Thickness checkbox, and enter the size even if there's plenty of empty space around the picture, so you may need to like the result, try again but this time, move your test strip over to the right a bit. General Query: If we want to remove a space at the end of a string variable, where there can be multiple spaces after the string elemets, how can this be done? For exmaple, supposing there is a string variable `x' and the elements of `x' are country names - Canada, Germany, Portugal etc.

FileMaker Pro 8 for Windows and Macintosh: Visual QuickStart Guide, You can base the trimming on the colour of the bottom right corner or trim off but was surrounded by unwanted space, which was trimmed using a single  The TRIM function is fully automatic. It removes removes both leading and trailing spaces from text, and also "normalizes" multiple spaces between words to one space character only. All you need to do is supply a reference to a cell. TRIM with CLEAN. If you also need to remove line breaks from cells, you can add the CLEAN function like so:

Illustrated Course Guide: Microsoft Word 2013 Advanced, Removing Unwanted Space Data varies: some runs Use fixed page margins and enter new numbers to adjust your Top, Bottom, Left, and Right margins. 4. Go to Tools | Options and click the Edit tab. In the right column under Editing Options, deselect the When Selecting, Automatically Select Entire Word check box and click OK.

Comments
  • that doens't work in android 4.1.2. I think it's some bug. Better not use CheckBox
  • For me not working , I am getting space right side of the check box, How to resolve this
  • For me not working, Getting space right side of the check box
  • @rams probably you have RTL enabled? in such case you probably would need to use -12dp