1

1 つのラジオ グループの下に 7 つのラジオ ボタンがあります。を使用して水平にレンダリングしましたorientation = "horizontal"。ただし、一度に表示できるのは 4 つだけで、残りは表示されません。

これらすべての「ラジオボタン」を 1 つの「RadioGroup」に保持しながら、残りを 2 行目に表示する方法はありますか?

私のコードが必要な場合 -

    <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それぞれに使用できます。したがって、それらの1つがチェックされている場合setChecked(false)は、他のものを呼び出します.

カスタム ドローアブルを使用して、チェックボックスではなくラジオ ボタンのように見えるようにします。

于 2015-04-10T06:23:28.570 に答える
0

すべてのラジオボタンの幅を設定してみてください

 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 を 2 つ追加しました。これらは行としてサーバーに表示されます。

<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 に答える