[英]LinearLayout with TextView on the left and RadioButton on the right?
Good afternoon, 下午好,
I am trying to do an alignment like this one : 我正在尝试进行这样的对齐:
http://i.imgur.com/ArAEiZC.png http://i.imgur.com/ArAEiZC.png
To do it I tried the following code : 为此,我尝试了以下代码:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="0sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<RadioButton android:id="@+id/radio_darkbackground"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:layout_gravity="right"
android:gravity="right"/>
</LinearLayout>
As you can see, I put the layout_gravity and gravity on "right" but it does not work and look like this : 如您所见,我将layout_gravity和gravity放在“正确”的位置,但是它不起作用,看起来像这样:
http://i.imgur.com/JDzwEJI.png http://i.imgur.com/JDzwEJI.png
change your code to this: 将您的代码更改为此:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<RadioButton android:id="@+id/radio_darkbackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:layout_gravity="right"/>
</FrameLayout>
Try This 尝试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="0sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<RadioButton
android:id="@+id/radio_darkbackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:gravity="right"
android:onClick="onRadioButtonClicked" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"></View>
<RadioButton
android:id="@+id/radio_darkbackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.