放置在相对布局中的带有单选按钮的RadioGroup(Android布局)

4
我想创建一个像下面这样简单的布局:
(o) Radio button A
(o) Radio button B [textedit]
    [x] checkbox

我已经创建了以下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>

看起来没问题,但问题是单选按钮之间没有连接,我的意思是它们可以同时被选中。 我认为这是因为即使它们都挂在同一个 <form> 下,第二个单选按钮也在另一个布局内:\ 有人有什么想法如何制作这种布局(主要是 [textedit] 紧贴 RadioButton B),使单选按钮也能正常工作? 非常感谢

2个回答

6

0

首先要尝试的是在关闭最后一个RadioButton之后立即关闭RadioGroup,而不是在最后关闭。更好的解决方案是将RelativeLayout作为整体容器。接下来添加你的RadioGroup和两个按钮,并关闭该组。根据布局的其余部分添加其他元素。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接