I want to put the text of a radio button on the left not on the right
I found this solution
<RadioGroup android:id="@+id/radios" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_gravity="right" android:inputType="text" android:orientation="vertical" > <RadioButton android:id="@+id/first" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="right" android:background="@color/white" android:button="@null" android:drawablePadding="30dp" android:drawableRight="@android:drawable/btn_radio" android:text="first" android:textColor="@color/Black" android:textSize="20dip" /> <RadioButton android:id="@+id/second" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/Black" android:button="@null" android:drawablePadding="30dp" android:drawableRight="@android:drawable/btn_radio" android:text="second" android:textColor="@color/White" android:textSize="20dp" /> <RadioButton android:id="@+id/third" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/Maroon" android:button="@null" android:drawablePadding="30dp" android:drawableRight="@android:drawable/btn_radio" android:text="third" android:textColor="@color/Vanilla" android:textSize="20dp" /> </RadioGroup>
but the problem is that the text gravity will be at the left what I want is to put it to right because i'm writing Arabic words
Open “res/layout/main. xml” file, add “RadioGroup“, “RadioButton” and a button, inside the LinearLayout . Radio button selected by default. To make a radio button is selected by default, put android:checked="true" within the RadioButton element.
By Default RadioGroup Will be in Vertical Orientaion , If you want to change use android:orientation="horizontal" attritube of RadioGroup . By Default RadioButton Will be in Left to Right Direction , If you want to change use android:layoutDirection="rtl" attritube of RadioButton .
RadioButton is a two states button which is either checked or unchecked. If a single radio button is unchecked, we can click it to make checked radio button. Once a radio button is checked, it cannot be marked as unchecked by user.
You can use android:checkedButton attribute on RadioGroup, providing the id of the RadioButton you want to be checked initially and selecting another RadioButton will clear the previous selection.
Try adding the following attributes into the RadioButton
, it should work, this way you still get to keep the ripple effect on the radio button:
android:layoutDirection="rtl" android:textAlignment="textStart" android:layout_gravity="start"
Remember to set supportsRtl
property to true in your application manifest.
for eg:
<RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="4dp" android:layoutDirection="rtl" android:textAlignment="textStart" android:layout_gravity="start" android:text="The test item a" android:textSize="14sp" /> .... </RadioGroup>
would give out:
Add android:gravity="right"
in each RadioButton
as follow..
<RadioGroup android:id="@+id/radios" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_gravity="right" android:inputType="text" android:orientation="vertical" > <RadioButton android:id="@+id/first" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="right" android:background="@color/white" android:button="@null" android:drawablePadding="30dp" android:drawableRight="@android:drawable/btn_radio" android:text="first" android:textColor="@color/Black" android:textSize="20dip" android:gravity="right"/> <RadioButton android:id="@+id/second" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/Black" android:button="@null" android:drawablePadding="30dp" android:drawableRight="@android:drawable/btn_radio" android:text="second" android:textColor="@color/White" android:textSize="20dp" android:gravity="right"/> <RadioButton android:id="@+id/third" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/Maroon" android:button="@null" android:drawablePadding="30dp" android:drawableRight="@android:drawable/btn_radio" android:text="third" android:textColor="@color/Vanilla" android:textSize="20dp" android:gravity="right" /> </RadioGroup>
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