2017-01-08 17 views
0

同じラジオグループの下にラジオボタンを上下左右に両方向に設定する方法はありますか? 2つの分離した行のように?この画像..Androidラジオボタンは、同じラジオグループの下に縦横両方向に設定されています

https://i.stack.imgur.com/4l3OW.png

 <RadioGroup 
    android:id="@+id/radiotheme" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp" 
    android:layout_marginTop="10dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <RadioButton 
      android:id="@+id/radiothemeblack" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textSize="15sp" 

      android:text="@string/theme_black" /> 

     <RadioButton 
      android:id="@+id/radiothemewhite" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:layout_weight="1" 
      android:textSize="15sp" 
      android:text="@string/theme_white" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

    <RadioButton 
     android:id="@+id/radiothemepink" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:layout_weight="1" 
     android:textSize="15sp" 
     android:text="@string/theme_pink" /> 

    <RadioButton 
     android:id="@+id/radiothemeblue" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:layout_weight="1" 
     android:textSize="15sp" 
     android:text="@string/theme_blue" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

    <RadioButton 
     android:id="@+id/radiothemegreen" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:layout_weight="1" 
     android:textSize="15sp" 
     android:text="@string/theme_green" /> 

     <RadioButton 
      android:id="@+id/radiothemebiolet" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:layout_weight="1" 
      android:textSize="15sp" 
      android:text="@string/theme_green" /> 

    </LinearLayout> 

</RadioGroup> 

ように私は、XMLによって、このようにしてみてください。問題はここではすべてのボタンを同時に選択することができました。どのように私はこの作業を正しく行うのですか?

答えて

0

私が知る限り、xmlでこれを行うことはできません。これを試してください。このXMLを

final RadioGroup radioGroup1 = (RadioGroup) findViewById(R.id.question1); 
final RadioGroup radioGroup2 = (RadioGroup) findViewById(R.id.question2); 

radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup radioGroup, int i) { 
       if (i != -1) 
        radioGroup2.check(-1); 
      } 
     }); 


radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup radioGroup, int i) { 
       if (i != -1) 
        radioGroup1.check(-1); 
      } 
     }); 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RadioGroup 
     android:id="@+id/question1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical"> 

     <RadioButton 
      android:id="@+id/radio0" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:text="RadioButton" /> 

     <RadioButton 
      android:id="@+id/radio1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RadioButton" /> 

     <RadioButton 
      android:id="@+id/radio2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RadioButton" /> 
    </RadioGroup> 

    <RadioGroup 
     android:id="@+id/question2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toEndOf="@+id/question1" 
     android:layout_toRightOf="@+id/question1" 
     android:orientation="vertical"> 

     <RadioButton 
      android:id="@+id/radio3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:text="RadioButton" /> 

     <RadioButton 
      android:id="@+id/radio4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RadioButton" /> 

     <RadioButton 
      android:id="@+id/radio5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RadioButton" /> 
    </RadioGroup> 
</RelativeLayout> 
関連する問題