Reputation: 931
How to make radio buttons in the radio group in the same alignment and put button in the right and text in the left on Android?
I want to make a radio group with radio buttons. I want to do it like this
My code does it like this:
How can I adjust the alignment of all the radio bottoms and how can I put the button on the right and text on the left?
I do it by padding
Here is my code:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_horizontal"
android:gravity="center|center_horizontal|center_vertical">
<RadioButton
android:id="@+id/ÅlandIslands"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Åland Islands" />
<RadioButton
android:id="@+id/Albania"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Albania" />
<RadioButton
android:id="@+id/Algeria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Algeria" />
<RadioButton
android:id="@+id/AmericanSamoa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="American Samoa" />
<RadioButton
android:id="@+id/Andorra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Andorra" />
</RadioGroup>
Upvotes: 1
Views: 582
Reputation: 8843
Your code is almost fine, You need to set each RadioButtons width to android:layout_width="match_parent"
so your each radio button will occupy full width of its parent layout.
It would be much better if you use recycler view as it would be easier to maintain in case of data changes and you could also implement features like search and sort with it.
Upvotes: 3