Change the side the text appears on a radio button

I wanted to do the same thing, without having to extend yet another class (or two, as you would have to at least extend CompoundButton and RadioButton) for something that should be part of the implementation from the beginning. Since I was using a RadioGroup, which will not work if you put say, a RadioButton and a TextView in a layout container. My solution is admittedly more than a bit hackish, but – it works.

1) Set Padding left to 40
2) Set Layout margin left to -36dp

At this point, the original radio button will be outside the view, and your text view will be sitting on the far left with a 4dp margin.

3) Set Drawable right to @android:drawable/btn_radio

You’ll now have a native RadioButton with the text on the left and a button on the right, that will work with a RadioGroup.

@CommonsWare

It’s worth mentioning that it’s incredibly ironic to bring up Human Interface Guidelines in response to this particular question. Especially considering that adjusting the RadioButton layout to place the button on the far right, would achieve consistency with the layout of the Spinner menu. I completely agree with your opinion on the matter – but it’s quite possible that NickTFried was trying to compensate for Android “hanging” itself in that regard.

Leave a Comment