2010-10-17 84 views
4

我想创建一个简单的布局类似如下:RadioGroup中具有相对的Android布局内的单选按钮

(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> 

它看起来正确,但问题在于单选按钮之间没有连接,我的意思是它们可以在同一时刻同时开启。 我认为这是因为即使他们挂在同一个第二个是在另一个布局内:\ 有没有人有一些想法我怎么能做出这种布局(主要是[textedit]刚好是RadioButton B),也开始工作radiobuttons? 非常感谢

回答

0

首先要尝试的是在关闭最后一个RadioButton而不是最后关闭RadioGroup。更好的解决方案是使用RelativeLayout作为整体容器。接下来添加您的RadioGroup和两个按钮并关闭组。相对于其他布局添加其他元素。