android - 水平单选按钮的大分布

标签 android layout radio-button

我在一行中有 3 个 RadioButton (linearLayout)。我想在行中正确分配它们,而不是将它们全部对齐到左侧,就像在 this screenshot 中一样。 .

目前是这样显示的:

enter image description here

XML:

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_below="@+id/linearLayout2"
            android:layout_alignLeft="@+id/linearLayout2" android:id="@+id/linearLayout3">
        <RadioGroup
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:orientation="horizontal">
            <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Yes"
                    android:id="@+id/radioButton3" android:layout_gravity="center_horizontal|top" android:checked="false"/>
            <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Maybe"
                    android:id="@+id/radioButton" android:layout_gravity="center_horizontal|top" android:checked="true"/>
            <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="No"
                    android:id="@+id/radioButton2" android:checked="false"/>
        </RadioGroup>
    </LinearLayout>

0dp ( see here ) 的经典按钮是可能的,但单选按钮在此设置下是不可见的。

有没有简单的方法可以做到这一点?

最佳答案

试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/linearLayout2"
    android:layout_below="@+id/linearLayout2" >
    <RadioGroup
            android:layout_width="fill_parent"
            android:weightSum="3"
            android:layout_height="fill_parent" android:orientation="horizontal">
        <RadioButton
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Yes"
                android:id="@+id/radioButton3" android:checked="false"/>
        <RadioButton
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Maybe"
                  android:layout_weight="1"
                android:id="@+id/radioButton" android:checked="true"/>
        <RadioButton
                android:layout_width="fill_parent"
                  android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="No"
                android:id="@+id/radioButton2" android:checked="false"/>
    </RadioGroup>
</LinearLayout>

关于android - 水平单选按钮的大分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16614503/

相关文章:

Java 选择布局问题

c# - MVVM:将单选按钮绑定(bind)到 View 模型?

javascript - 如果... radio 被检查警报

java - 检测到设备正在关闭?

安卓数字小键盘

android - 在布局中动态添加布局?

java - 关于 JPanels 和菜单的最佳选择

android - GridView 的项目之间的空间

android - 绘制带有空白区域的位图

python - 如何使用 python Selenium 单击单选按钮