I have the following radio buttons inside a radio group of similar buttons. By default a button is on the left of the associated text. How do I get the button itself to be on the right of the associated text?
<RadioGroup
android:id="@+id/points_radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/do_tastk_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="doTask1"
android:paddingLeft="40dip"
android:text="@string/task_name_1"
android:textColor="#000000" />
<RadioButton
android:id="@+id/do_tastk_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="doTask2"
android:paddingLeft="40dip"
android:text="@string/task_name_2"
android:textColor="#000000" />
</RadioGroup>
To make a horizontal radio button set, add the data-type="horizontal" to the fieldset . The framework will float the labels so they sit side-by-side on a line, hide the radio button icons and only round the left and right edges of the group.
Yes, there is a way. Drag a radio list widget to your screen, go to the Properties tab and select 'Orientation' -> Horizontal.
To label a radio button, add a <label> element after the <input> element and insert a for attribute with the same value as the id of the associated <input> element. Then, write your label text in the <label> tag.
Use
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
So your code will be like:
<RadioGroup
android:id="@+id/points_radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/do_tastk_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:onClick="doTask1"
android:paddingLeft="40dip"
android:text="@string/task_name_1"
android:textColor="#000000" />
<RadioButton
android:id="@+id/do_tastk_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:onClick="doTask2"
android:paddingLeft="40dip"
android:text="@string/task_name_2"
android:textColor="#000000" />
</RadioGroup>
by using
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
you change radio button format. It is better practice just to align right,
android:layoutDirection="rtl"
on each radioButton, and text will be on left side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With