I want to have the "label", - the text you set in your RadioButton
to show left of the button and have some padding in between.
Adding an additional TextView
into the layout doesn't work because my RadioGroup
does not work (i can choose multiple buttons) if i add anything other then a RadioButton
into the RadioGroup
.
So, how can i change the RadioButton to be <text><buttondrawable>
instead of <buttondrawable><text>
You can achieve this by setting
android:button="@null"
and adding the drawable of theRadioButton
asandroid:drawableRight
. You can change the Padding between the text and the drawable withandroid:drawablePadding
.The answer above makes the image have no selected state.
May this help you:
On API <= 16 you can set padding left 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 left padding is in relation to the radio button drawable. Same applies to the about a patch nine. To better illustrate padding differences see the attached screen shot.
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 You should have radio button style for the min sdk you are supporting and another style for api 17+
the answer is from this same question answered by @James Baca