如标题所述,我正在尝试将 3x3 单选按钮网格分组到一个单选组中。在之前的一个问题中,我了解到要使单选按钮对应于单个组,它们必须是它们将对应的单选组的直接子级。当我试图将整个表格布局(表格行中的单选按钮)封装在一个单选组中时,我很难学到这一点。
碰到那堵墙,我尝试了以下操作:
<TableLayout android:id="@+id/table_radButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_radGroup_buffer">
<TableRow>
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/radGroup1">
<RadioButton android:id="@+id/rad1"
android:text="Button1"
android:layout_width="105px"
android:layout_height="wrap_content"
android:textSize="13px"></RadioButton>
<RadioButton android:id="@+id/rad2"
android:text="Button2"
android:layout_width="105px"
android:textSize="13px"
android:layout_height="wrap_content"></RadioButton>
<RadioButton android:id="@+id/rad3"
android:text="Button3"
android:layout_width="105px"
android:textSize="13px"
android:layout_height="wrap_content"></RadioButton>
</RadioGroup>
</TableRow>
<TableRow>
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/radGroup1">
<!-- snippet -->
</TableRow>
<!-- snippet --->
</TableLayout>
很明显我第一次没有学到,因为我又碰壁了。我希望不同表格行中的单选按钮会注意到它们属于同一个单选组(为每个组提供相同的 ID),但这没有用。
有什么办法可以将所有这些按钮分组到一个单选组中,并且仍然保持我的 3x3 结构(3 行,每行 3 个单选按钮)?
原文由 Fizz 发布,翻译遵循 CC BY-SA 4.0 许可协议
实际上,如果你
TableLayout
就像这个例子一样,这并不难并创建这样的布局(当然你需要清理它,但你明白了)