0

I am trying to create a RadioButton in android. My requirement is that the label should be always left aligned and icon should be right aligned(evenly distributed, as first item in attached screenshot). I was able to achieve it. But this is not working when the label has no character and only digits between 0 to 9. I also tried adding space, but no luck. Can someone please help?

<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listRadioItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:ellipsize="end"
android:layoutDirection="rtl"
android:maxLines="1"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:text="123"
android:layout_gravity="start"
android:textAlignment="textStart" />

enter image description here

Sohan
  • 66
  • 1
  • 4

1 Answers1

0

I think the easiest solution, if you know it always needs to be left-aligned, is to use

android:layoutDirection="rtl"
android:gravity="center_vertical|left"

Otherwise it might be worth looking into formatting for RTL text because I think the handling of numbers is what's causing that behaviour, where "start" and "end" become flipped (because you don't necessarily want to reverse a number, so it might be treated as LTR - I'm not an expert on any of this though!)

cactustictacs
  • 17,935
  • 2
  • 14
  • 25