【发布时间】:2015-04-10 06:18:06
【问题描述】:
我在一个单选组下有 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>
【问题讨论】:
-
为什么要将它们全部保存在一个 RadioGroup 中(在布局文件中)?您可以轻松地在源中实现一个无线电组,即保留该组的所有radiobutton的列表,并设置侦听器,该侦听器在选中一个按钮时禁用组中所有其他RadioButtons。
-
嗯,这听起来像是一个解决方案,但不是一个干净的解决方案。我认为必须有一些解决方案来满足我的需求。
-
@Hasina 您已使用相同问题的链接将此问题标记为重复:)
标签: android android-radiobutton