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-line.
As-is, the text is way too close to the checkbox:
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-line.
As-is, the text is way too close to the checkbox:
I hate to answer my own question, but in this case I think I need to. After checking it out, @Falmarri was on the right track with his answer. The problem is that Android's CheckBox control already uses the android:paddingLeft property to get the text where it is.
The red line shows the paddingLeft offset value of the entire CheckBox
If I just override that padding in my XML layout, it messes up the layout. Here's what setting paddingLeft="0" does:
Turns out you can't fix this in XML. You have do it in code. Here's my snippet with a hardcoded padding increase of 10dp.
final float scale = this.getResources().getDisplayMetrics().density;
checkBox.setPadding(checkBox.getPaddingLeft() + (int)(10.0f * scale + 0.5f),
checkBox.getPaddingTop(),
checkBox.getPaddingRight(),
checkBox.getPaddingBottom());
This gives you the following, where the green line is the increase in padding. This is safer than hardcoding a value, since different devices could use different drawables for the checkbox.