Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

how to put the text on the left of a radio button in android

I want to put the text of a radio button on the left not on the right

I found this solution

        <RadioGroup
        android:id="@+id/radios"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_gravity="right"
        android:inputType="text"
        android:orientation="vertical" >

        <RadioButton
            android:id="@+id/first"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:background="@color/white"
            android:button="@null"
            android:drawablePadding="30dp"
            android:drawableRight="@android:drawable/btn_radio"
            android:text="first"
            android:textColor="@color/Black"
            android:textSize="20dip" />

        <RadioButton
            android:id="@+id/second"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/Black"
            android:button="@null"
            android:drawablePadding="30dp"
            android:drawableRight="@android:drawable/btn_radio"
            android:text="second"
            android:textColor="@color/White"
            android:textSize="20dp" />

        <RadioButton
            android:id="@+id/third"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/Maroon"
            android:button="@null"
            android:drawablePadding="30dp"
            android:drawableRight="@android:drawable/btn_radio"
            android:text="third"
            android:textColor="@color/Vanilla"
            android:textSize="20dp" />
    </RadioGroup>

but the problem is that the text gravity will be at the left what I want is to put it to right because i'm writing Arabic words

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try adding the following attributes into the RadioButton, it should work, this way you still get to keep the ripple effect on the radio button:

android:layoutDirection="rtl"
android:textAlignment="textStart"
android:layout_gravity="start"

Remember to set supportsRtl property to true in your application manifest.

for eg:

   <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:layoutDirection="rtl"
            android:textAlignment="textStart"
            android:layout_gravity="start"
            android:text="The test item a"
            android:textSize="14sp" />

         ....                       

    </RadioGroup>

would give out:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...