1

我在一个单选组下有 7 个单选按钮。我使用orientation = "horizontal". 但一次只能看到 4 个,其余的则不可见。

有什么方法可以在第二排显示其余的按钮,同时将所有这些“单选按钮”保留在一个“单选组”中?

如果您需要我的代码 -

    <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1.5 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2.5 BHK" />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2.5 BHK" />
</RadioGroup>
4

7 回答 7

1

您不能将RadioButtons它们放置在屏幕上的不同位置,同时保持它们相同RadioGroup。您也不能将它们放在不同的行中(就像您想要实现的那样)。是的,我也讨厌。

您可以制作复选框,按照您想要的方式放置它们,然后setOnCheckedChangedListener在每个复选框上使用。因此,如果其中一个被选中,请致电setChecked(false)其他人。

使用自定义可绘制对象,使它们看起来像单选按钮而不是复选框。

于 2015-04-10T06:23:28.570 回答
0

我也在里面试试这个RadioGroup,你一次只能选择一个,效果很好: 在此处输入图像描述

<RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton android:layout_height="match_parent" >
        </RadioButton>

        <RadioButton android:layout_height="match_parent" >
        </RadioButton>

        <RadioButton android:layout_height="match_parent" >
        </RadioButton>

        <RadioButton android:layout_height="match_parent" >
        </RadioButton>

        <RadioButton android:layout_height="match_parent" >
        </RadioButton>

        <RadioButton android:layout_height="match_parent" >
        </RadioButton>

        <RadioButton android:layout_height="match_parent" >
        </RadioButton>
    </RadioGroup>
于 2015-04-10T07:08:02.933 回答
0

您可以在这样的广播组中使用滚动视图

                 <RadioGroup
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:orientation="horizontal">
                <HorizontalScrollView
                   android:id="@+id/ScrlView"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content" >

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1 BHK" />

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1.5 BHK" />

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2 BHK" />

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2.5 BHK" />
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2 BHK" />

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2.5 BHK" />
                     </ScrollView>
</RadioGroup>
于 2015-04-10T06:24:59.183 回答
0

我想,没有足够的地方容纳所有人。尝试设置所有 RadioButtons android:layout_width="0dp"android:layout_weight="1"但它可能不是很漂亮。

于 2015-04-10T06:27:50.307 回答
0

尝试为所有 Radiobutton 设置宽度

 android:layout_width="0dp"

android:layout_weight="1"为每个单选按钮添加。

前任

 <RadioButton
                 android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="1 BHK" 
android:layout_weight="1"/>
于 2015-04-10T06:35:38.807 回答
0

从您的 xml 代码中替换以下代码

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1.5 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2.5 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2 BHK" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2.5 BHK" />
        </RadioGroup>
    </LinearLayout>
</HorizontalScrollView>
于 2015-04-10T06:41:34.817 回答
-1

我对此的解决方案是在 RadioGroup 布局中添加一个 LinearLayout。我将 RadioGroup 的方向更改为垂直,并添加了两个具有水平方向的 LinearLayout,它们将作为行提供服务。

<RadioGroup
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"        
    >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1 BHK" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1.5 BHK" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2 BHK" />

    </LinearLayout>


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

         <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2.5 BHK" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3 BHK" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3.5 BHK" />

    </LinearLayout>
</RadioGroup>
于 2015-04-10T06:45:50.793 回答