2014-09-25 73 views
0

嗨我几天前开始为android开发,并且我尝试使用Radio组尝试使用Radio组。在我的代码中,出于某种原因,所有的单选按钮都可以一起选择。 有什么建议吗?不管怎么说,还是要谢谢你。无线电组android

XML:

<RadioGroup 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/rG"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="89dp" 
       android:layout_below="@id/title" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true"> 

       <RadioButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="95" 
        android:layout_marginLeft="75sp" 
        android:layout_marginTop="20sp" 
        android:id="@+id/rb95" 
        android:layout_gravity="left|top" 
        android:checked="true"/> 

       <RadioButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="98" 
        android:id="@+id/rb98" 
        android:layout_gravity="right|top" 
        android:layout_alignTop="@+id/rb95" 
        android:layout_alignLeft="@+id/rbs" 
        android:layout_alignStart="@+id/rbs" /> 

       <RadioButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="96" 
        android:id="@+id/rb96" 
        android:layout_gravity="left" 
        android:layout_below="@id/rb95" 
        android:layout_alignLeft="@id/rb95" 
        android:layout_alignStart="@id/rb95" /> 

       <RadioButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="soler" 
        android:id="@+id/rbs" 
        android:layout_gravity="right" 
        android:layout_marginRight="75dp" 
        android:layout_alignTop="@id/rb96" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentEnd="true" /> 
      </RelativeLayout> 
     </RadioGroup> 



enter code here 

回答

1

拉单选按钮出的RelativeLayout的(完全摆脱它:它不是只有放错地方,也没用),并预期他们将工作。

如果你真的需要的RelativeLayout作为RadioGroup中一个容器,然后交换的RelativeLayout和RadioGroup中(RelativeLayout的上

+0

我已经与删除相对布局的问题是,我想在2 2平方米的4个按钮是否有其他方式来做到这一点? – dorbt12 2014-09-25 18:44:24

+1

...将2个垂直RadioGroup并排放置? – 2014-09-25 18:45:43

+0

但我希望他们在同一组 – dorbt12 2014-09-25 18:46:15

0

我觉得你的问题是,你有你的relativeLayout里面RadioGroup

Here单选按钮上的Google开发者页面。

+0

我已经与删除相对布局的问题是,我想在2乘2平方4按钮是否有其他方式来做到这一点? – dorbt12 2014-09-25 18:45:38

+0

当然,您可以使用标志来检查哪些按钮被点击。该组只是为了方便,但如果您真的想要,您可以编程每个按钮并放置两个或两个或全部四个按钮 – 2014-09-25 18:47:12