Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Radio button alignment 2 x 2 in one radiogroup

I have 4 radio buttons and i can only align them vertically and horizontally alignment like this:

A B C D 

and

A
B
C
D

but I want is this kind alignment:

A B
C D

is there any possible way to do this?, I can't find any right tutorials or examples.

like image 303
Drenyl Avatar asked Jan 29 '16 10:01

Drenyl


2 Answers

Use LinearLayout within Radiogroup Like this:

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/radioGroup">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New RadioButton"

            android:layout_marginLeft="5dp"/>

        <RadioButton
            android:id="@+id/radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New RadioButton"

            android:layout_marginRight="5dp"    />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RadioButton
            android:id="@+id/radioButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New RadioButton"

            android:layout_marginLeft="5dp"/>

        <RadioButton
            android:id="@+id/radioButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New RadioButton"

            android:layout_marginRight="5dp"/>
    </LinearLayout>
</RadioGroup>
like image 137
Gagan Sethi Avatar answered Oct 05 '22 11:10

Gagan Sethi


RadioGroup extends android.widget.LinearLayout so it is not possible. If you want them in a grid use the appropriate layout but you have to do the whole logic of selecting only one item and so on on your own

like image 34
and_dev Avatar answered Oct 05 '22 11:10

and_dev