Good afternoon,
I am trying to do an alignment like this one :
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 :
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.