I have a textview on the left side and RadioGroup on the right side. Before I put my buttons in a radio group I had the buttons on the right side of the screen. What I am doing wrong after putting it in a RadioGroup?
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/radioButton1"
android:layout_alignParentLeft="true"
android:text="@string/hair"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/Yes" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radioButton1"
android:layout_below="@+id/radioButton1"
android:text="@string/No" />
</RadioGroup>
</RelativeLayout>
All of the “align” parameters that you have set on the buttons individually (like
layout_alignParentRight) are no longer valid because the buttons are inside of aRadioGroup, which is a subclass ofLinearLayout. In order to right-align the group as a whole, you need to add the proper parameters to theRadioGroupitself.Also, you may want the
RadioGroupwidth towrap_contentinstead offill_parent. Otherwise any horizontal layout alignments you do will likely not be visible with the container trying to fill up all available space.HTH