Is there an easy way to add padding between the checkbox in a CheckBox control, and the associated text?
I cannot just add leading spaces, because my label is multi-
In my case I solved this problem using this following CheckBox attribute in the XML:
*
android:paddingLeft="@dimen/activity_horizontal_margin"
*
Android 4.2 Jelly Bean (API 17) puts the text paddingLeft from the buttonDrawable (ints right edge). It also works for RTL mode.
Before 4.2 paddingLeft was ignoring the buttonDrawable - it was taken from the left edge of the CompoundButton view.
You can solve it via XML - set paddingLeft to buttonDrawable.width + requiredSpace on older androids. Set it to requiredSpace only on API 17 up. For example use dimension resources and override in values-v17 resource folder.
The change was introduced via android.widget.CompoundButton.getCompoundPaddingLeft();
This behavior appears to have changed in Jelly Bean. The paddingLeft trick adds additional padding, making the text look too far right. Any one else notice that?
For space between the check mark and the text use:
android:paddingLeft="10dp"
But it becomes more than 10dp, because the check mark contains padding (about 5dp) around. If you want to remove padding, see How to remove padding around Android CheckBox:
android:paddingLeft="-5dp"
android:layout_marginStart="-5dp"
android:layout_marginLeft="-5dp"
// or android:translationX="-5dp" instead of layout_marginLeft
<CheckBox
android:paddingRight="12dip" />
Use attribute android:drawableLeft
instead of android:button
. In order to set padding between drawable and text use android:drawablePadding
. To position drawable use android:paddingLeft
.
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:drawableLeft="@drawable/check_selector"
android:drawablePadding="-50dp"
android:paddingLeft="40dp"
/>