简体   繁体   中英

RadioButton align text to left side and button to right

I would like my radio button to have width matching the screen and have its text aligned to left side of the screen and button to the right. Currently my layout looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RadioGroup
        android:id="@+id/optionsContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RadioButton
            android:id="@+id/sortingOptionRadioButton"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            xmlns:tools="http://schemas.android.com/tools"
            android:layoutDirection="rtl"
            android:text="Popularity"
            android:layout_margin="@dimen/e2_space_small"
            />
    </RadioGroup>

</LinearLayout>

And in preview it looks just like I want, but when I launch the application on my device then both text and button are aligned to the right side. How can I have text and button be aligned to opossed sides?

try by adding layout gravity and gravity attribute inside both radio button group and radio button

 android:layout_gravity="start"
 android:gravity="left"

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM