Pavle37
Pavle37

Reputation: 581

Android RadioGroup button gravity

As i was developing an app and i needed radio buttons, i decided to create a RadioGroup and inside it, i created 3 RadioButtons and i wanted to position them to the left, center, and right accordingly.

I put android:orientation:"horizontal" in RadioGroup and i have placed android:layout_gravity="left right or center in RadioButtons created inside RadioGroup, but it just places the buttons next to each other aligned left, and distorts the text a little bit.

Same thing happens if i apply android:gravity="left" to the buttons.

I am not sure how to align first button on the left side, second on the center, and third on the right side.

Thanks!

Upvotes: 2

Views: 2651

Answers (1)

Mohammad Rahchamani
Mohammad Rahchamani

Reputation: 5220

try this in your layout :

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="3"
    android:orientation="horizontal">
    <RadioButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="1"/>
    <RadioButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="2"/>
    <RadioButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="3"/>
    </RadioGroup>

Upvotes: 3

Related Questions