Add margin between a RadioButton and its label in Android?
For anyone reading this now, the accepted answer will lead to some layout problems on newer APIs causing too much padding.
On API <= 16 you can set paddingLeft
on the radio button to set the padding relative to the radio button's view bounds. Additionally, a patch nine background also changes the view bounds relative to the view.
On API >= 17 the paddingLeft
(or paddingStart
) is in relation to the radio button drawable. Same applies to the about a patch nine. To better illustrate padding differences see the attached screenshot.
If you dig through the code you will find a new method in API 17 called getHorizontalOffsetForDrawables. This method is called when calculating the left padding for a radio button(hence the additional space illustrated in the picture).
TL;DR Just use paddingLeft
if your minSdkVersion
is >= 17. If you support API <= 16, you should have radio button style for the min SDK you are supporting and another style for API 17+.
Not sure if this will fix your problem, but have you tried Radio Button's "Padding left" property with a value of 50dip or more
i tried several ways and finished with this one working correctly on both emulator and devices:
<RadioButton
android:background="@android:color/transparent"
android:button="@null"
android:drawableLeft="@drawable/your_own_selector"
android:drawablePadding="@dimen/your_spacing" />
- android:background needs to be transparent as it seems on api10 there is a background with intrinsic paddings (not tried with other apis but the solution works on others too)
- android:button needs to be null as paddings will not work correctly otherwise
- android:drawableLeft needs to be specified instead of android:button
- android:drawablePadding is the space that will be between your drawable and your text