![](/img/trans.png)
[英]TableLayout of radiogroup(s) with respective label(s) aligned in android
[英]RadioGroup Right Aligned in Android
我在左侧有一个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>
您单独在按钮上设置的所有“ align”参数(例如layout_alignParentRight
)都不再有效,因为按钮位于RadioGroup
,后者是LinearLayout
的子类。 为了使组整体右对齐,您需要将适当的参数添加到RadioGroup
本身。
另外,您可能希望RadioGroup
宽度为wrap_content
而不是fill_parent
。 否则,在尝试填充所有可用空间的容器中,您所做的任何水平布局对齐方式都可能不可见。
HTH
您也可以将其添加到RadioGroup
,它也可以正常工作!
android:gravity="center|left"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.