Android checkbox spacing checkbox

Hi, I am trying to create a list of checkboxes that should look like the image below, which will take place before and after the checkmark image.

enter image description here

but when I try to create a checkbox, it displays as below.

enter image description here

there is no space surrounding the tagged image, as shown in the first image. If I use the add-on to add a flag to it like "android: padding = 50dp" , it gives the space between the tag image and the text. But leaving no space at the beginning of the .ie in front of the Check-Mark image. below is my xml layout for checkbox

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="15dp"> <CheckBox android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/btn_check_square" android:background="@drawable/filter_item_background" android:textColor="@android:color/black" android:padding="5dp" android:text="check box text"/> </LinearLayout> 

Any help in solving this problem is appreciated.

+4
source share
5 answers

this is permitted using the code below.

 <CheckBox android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/filter_item_background" android:button="@android:color/transparent" //Make button null android:drawableLeft="@drawable/btn_check_square" //Create button in drawable android:drawablePadding="20dp" //Set space between Text & CB android:padding="5dp" android:text="check box text" android:textColor="@android:color/black" /> 
+26
source

Try this (without special graphics):

 <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@android:color/transparent" android:drawablePadding="8dp" android:text="CheckBox" /> 

It uses a little trick: since the Checkbox is derived from Button, we can add drawable and now we can indent between the label and drawable. Since we do not need a real icon, we use a transparent color instead.

+13
source
 <CheckBox android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/filter_item_background" android:button="@null" //Make button null android:drawableLeft="@drawable/btn_check_square" //Create button in drawable android:drawablePadding="20dp" //Set space between Text & CB android:padding="5dp" android:text="check box text" android:textColor="@android:color/black" /> 
+2
source

Use the code below

 final float scale = this.getResources().getDisplayMetrics().density; checkbox.setPadding(checkbox.getPaddingLeft() + (int) (10.0f * scale + 0.5f), checkbox.getPaddingTop(), checkbox.getPaddingRight(), checkbox.getPaddingBottom()); 
+1
source

Add this to your checkbox:

 android:layout_marginLeft="5dp" android:layout_marginRight="5dp" 
0
source

All Articles