In the XML to follow, each RadioButton is set to android:gravity="center".
All three buttons show up, but the button descriptions are centered. The buttons themselves are not. How do I center the buttons as well as their descriptions?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center"
android:checked="true"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center"
android:text="RadioButton" />
</RadioGroup>
</LinearLayout>
In this picture, you can ignore the top bar. That’s already been coded in. What I’m seeing is the RadioButtons far to the right of the “RadioButton” text (the button itself is up against the layout bounds). The desired end result is, since I can’t post images: Here it is.
I have tried editing your layout to do what is in your screenshot. I don’t think this is an efficient way to do this but this is the only way that worked for me.
I inserted every radiobutton inside a parent linerlayout, and then used gravity center.
I really hope there’s a better solution than this. But here, hope it helps. 🙂