Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I align radio buttons to the right of associated text?

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>
like image 489
learner Avatar asked Apr 21 '13 15:04

learner


People also ask

How do I put radio buttons side by side in HTML?

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.

How do I align a radio button horizontally?

Yes, there is a way. Drag a radio list widget to your screen, go to the Properties tab and select 'Orientation' -> Horizontal.

How do I make radio buttons with text?

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.


2 Answers

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>
like image 170
stinepike Avatar answered Oct 19 '22 18:10

stinepike


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.

like image 19
Andracchi Avatar answered Oct 19 '22 18:10

Andracchi