matip
matip

Reputation: 900

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?

Upvotes: 1

Views: 644

Answers (1)

PushpikaWan
PushpikaWan

Reputation: 2545

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

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

Upvotes: 1

Related Questions