2014-09-25 74 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