[英]RadioGroup with radiobuttons inside a relative android layout
I want to create a simple layout like the following: 我想创建一个如下所示的简单布局:
(o) Radio button A
(o) Radio button B [textedit]
[x] checkbox
For that I've created the following layout.xml: 为此,我创建了以下layout.xml:
<RadioGroup
android:layout_above="@+id/RadioButton_Count"
android:id="@+id/RadioGroup01"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<RadioButton
android:layout_height="wrap_content"
android:id="@+id/RadioButton_A"
android:text="Play forever"
android:checked="true"
android:layout_width="fill_parent"
android:textSize="20sp">
</RadioButton>
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/RadioButton_B"
android:text="Count:"
android:textSize="20sp">
</RadioButton>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/EditText_NumCount"
android:inputType="number"
android:layout_toRightOf="@+id/RadioButton_B"
android:width="70sp" >
</EditText>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/CheckBox_StopCount"
android:text="Stop"
android:layout_below="@+id/RadioButton_B"
android:textSize="18sp">
</CheckBox>
</RelativeLayout>
</RadioGroup>
It looks right, but the problem is that the radiobuttons doesn't connect between each other, i mean that they can be both on in the same moment. 它看起来是正确的,但问题是radiobuttons之间没有连接,我的意思是它们可以在同一时刻同时开启。 I think it's because even if they're hanging from the same the second one is inside another layout :\\ Does anyone have some idea how could I make this kind of layout (Mainly the [textedit] just right the RadioButton B), getting working also the radiobuttons? 我认为这是因为即使它们是悬挂在同一个第二个是在另一个布局内:\\有没有人有一些想法我怎么能做这种布局(主要是[textedit]恰到好处的RadioButton B),开始工作radiobuttons? Thank you very much 非常感谢你
You simply can't do it. 你根本做不到。 I was also trying to do something similar and got stuck. 我也试图做类似的事情而陷入困境。
"RadioButtons have to be direct children of RadioGroup." “RadioButtons必须是RadioGroup的直接子女。” https://code.google.com/p/android/issues/detail?id=1214 https://code.google.com/p/android/issues/detail?id=1214
The first thing to try is to close your RadioGroup right after you close the last RadioButton instead of at the end. 首先要尝试的是在关闭最后一个RadioButton而不是结束后关闭你的RadioGroup。 A better solution is to use a RelativeLayout as the overall container. 更好的解决方案是使用RelativeLayout作为整体容器。 Next add your RadioGroup and both buttons and close the group. 接下来添加您的RadioGroup和两个按钮并关闭该组。 Add the other elements relative to the rest of the layout. 相对于布局的其余部分添加其他元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.