Skip to content Skip to sidebar Skip to footer

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 r

Solution 1:

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>

Solution 2:

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.

Solution 3:

You can do in xml

<android.support.v7.widget.AppCompatRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|center" //or "center_vertical"for center text
android:layoutDirection="rtl"
android:text="hello" />

Following line is enough

android:layoutDirection="rtl"

Solution 4:

easy way add this to your radiobutton in xml

android:layoutDirection="rtl"

Solution 5:

If you plan to add elements dynamically you can try to create a layout with a textview and a radio button with no text on the right. Something on these lines:

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><RadioButtonandroid:id="@+id/radiobutton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentTop="true"/><TextViewandroid:id="@+id/textview"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/radiobutton"android:layout_alignBottom="@+id/radiobutton"android:layout_alignParentLeft="true">

Post a Comment for "How Can I Align Radio Buttons To The Right Of Associated Text?"