其他分享
首页 > 其他分享> > Android:单个放射线组中的单选按钮对齐2 x 2

Android:单个放射线组中的单选按钮对齐2 x 2

作者:互联网

我有4个单选按钮,我只能将它们垂直和水平对齐,如下所示:

A B C D 

A
B
C
D

但我想要的是这种对齐方式:

A B
C D

有什么可能的方法吗?,我找不到任何正确的教程或例子.

解决方法:

在Radiogroup中使用LinearLayout像这样:

<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>

标签:android,radio-button,android-radiobutton
来源: https://codeday.me/bug/20190829/1760517.html