2016-07-22 3 views
0

RadioButtonをRelativeLayoutと同じようにRadioGroup内に揃える必要があります。私は、RadioGroupがLinearLayoutから継承されている可能性があり、その中にRelativeLayoutのような内容を配置できない可能性があることを読みました。私が実装しようとしている実際の事は、RadioGroup内の2行です。最初の行には2つのRadioButtonがあり、2行目には別のボタンを追加する必要があります。どうすればいい?ラジオグループ内のラジオボタンをアンドロイドで整列させるにはどうすればいいですか?

答えて

0

このレイアウトを試して、それがあなたに役立つかどうか教えてください。必要に応じて修正することができます。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

<RadioGroup 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="5dp"> 

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

     <RadioButton 
      android:id="@+id/radioButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Blue"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

    </LinearLayout> 
</RadioGroup> 

</LinearLayout> 

Layout screenshot

+0

が機能しません。整列はOKです。ラジオ・グループとして振る舞いません。複数のボタンを選択できます。 –

1

あなたがする必要があるのは、コードの下にチェックアウト水平にそれらを揃えるために、水平方向に対してラジオグループ向きを設定されています。

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:padding="@dimen/activity_horizontal_margin"> 


    <RadioGroup 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:layout_height="match_parent"> 

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

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New RadioButton" 
      android:id="@+id/radioButton2" /> 
    </RadioGroup> 
    <RadioButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New RadioButton" 
     android:layout_gravity="start" 
     android:id="@+id/radioButton3" /> 

</LinearLayout> 
関連する問題