我在左侧有一个 textview,在右侧有一个 RadioGroup。在我将按钮放入单选组之前,我的按钮位于屏幕的右侧。将它放入 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>
最佳答案
您在按钮上单独设置的所有“对齐”参数(如 layout_alignParentRight
)不再有效,因为按钮位于 RadioGroup
内,它是 LinearLayout
的子类。为了将组作为一个整体右对齐,您需要将适当的参数添加到 RadioGroup
本身。
此外,您可能希望 RadioGroup
宽度为 wrap_content
而不是 fill_parent
。否则,当容器试图填满所有可用空间时,您所做的任何水平布局对齐都可能不可见。
HTH
关于android - RadioGroup 在 Android 中右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8451059/