我有多个单选按钮,我想使用表格对其进行布局,但也将它们包含在一个单选按钮组中。我有以下 xml 布局:
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/Group1">
<TableLayout android:id="@+id/RadioButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<RadioButton android:id="@+id/rad1"
android:text="RButton1"
android:layout_width="105px"
android:layout_height="wrap_content"
android:textSize="13px"></RadioButton>
<RadioButton android:id="@+id/rad2"
android:text="RButton2"
android:layout_width="105px"
android:textSize="13px"
android:layout_height="wrap_content"></RadioButton>
<RadioButton android:id="@+id/rad3"
android:text="RButton3"
android:layout_width="105px"
android:textSize="13px"
android:layout_height="wrap_content"></RadioButton>
</TableRow>
</TableLayout>
</RadioGroup>
但不幸的是,表格内的单选按钮似乎忽略了它们位于 RadioGroup 标签内这一事实,因此您可以同时选择多个单选按钮。我注意到,通过删除表格并仅使用单选按钮,它就可以正常工作。我怎样才能克服这个?它会像在表内而不是表外声明 radio 组一样简单吗?谢谢你的帮助。
最佳答案
您的 RadioButton
小部件必须是 RadioGroup
的直接子级才能使组效果起作用。
关于xml - 如何将单选组添加到表格内的单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2361205/