Reputation: 4381
I'm trying to work out how to correctly align text to radio buttons. I have a number of radio buttons laid out vertically in a radio group and a TextView for each radio button that should line up with the radio button. The problem i'm finding is that because the radio buttons are in their own RadioGroup layout I can't reference the RadioButton so it lines up with the TextView. Does anyone know a good way of doing this?
Upvotes: 0
Views: 3243
Reputation: 11
You can use a Relative Layout instead of a Linear Layout. In relative layouts, the positioning of a view is always relative to another. That way, you can define the position of your TextView, and then anchor the RadioGroup to it using layout_below, layout_above, layout_toRightOf, layout_toLeftOf, etc.
Upvotes: 1
Reputation: 48871
A RadioGroup is derived from ViewGroup - you could enumerate the children (RadioButtons) using the getChildCount and getChildAt methods and, in turn, as RadioButtons are derived from View, use getBottom / getTop to find each RadioButton's relative position within the RadioGroup.
Upvotes: 0
Reputation: 8533
Have you tried to nest a LinearLayout inside the RadioGroup and put the TextView and RadioButton within it? I haven't tried myself so I don't know if it works.
Upvotes: 1
Reputation: 548
every radiobutton has a text by default: android:text
. do you really need another textview for each radiobutton?
Upvotes: 0