0

Having layout as content for ALertDialog like:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center"
>

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="30dp"
    android:paddingBottom="30dp"
    android:paddingLeft="35dp"
    android:paddingRight="35dp">

    <RadioButton
        android:id="@+id/bt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/radiobutton_selector"
        android:text="button one" />

    <RadioButton
        android:id="@+id/bt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/radiobutton_selector"
        android:text="button two" />
</RadioGroup>

<LinearLayout> ... </LinerLayout>
</LinearLayout>

In under api level 16 the RadioButton has much more space in left side of the dialog. tried following seems not working:

group.setPadding(10, 10, 10, 10); 

Is there different way to do it? How to set the padding dynamically for different api level?

lannyf
  • 9,865
  • 12
  • 70
  • 152

1 Answers1

0

This can be achievedby setting android:button="@null" and android:drawableLeft ="name".

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

        <RadioButton
            android:id="@+id/first"
            android:button="@null"
            android:drawableRight="@android:drawable/btn_radio"
            android:drawablePadding="20dp"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="@string/first"
            android:textSize="20dip" />

        <RadioButton
            android:id="@+id/second"
            android:button="@null"
            android:drawableRight="@android:drawable/btn_radio"
            android:drawablePadding="20dp"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="@string/second"
            android:textSize="20dip" />
    </RadioGroup>
  • Padding between the and drawable is set with android:drawablePadding="10dp"

On API <= 16 you can set padding left on the radio button to set the padding relative to the radio button's view bounds. Additionally a patch nine background also changes the view bounds relative to the view.

On API 17 the left padding is in relation to the radio button drawable. Same applies to the about a patch nine.

This answer is based on @James Baca answer from question

Community
  • 1
  • 1
Amarjit
  • 4,327
  • 2
  • 34
  • 51