Radio transition spaces leftDrawable & rightDrawable

I have RadioGroup

with switches:

  <RadioGroup 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/radioGroup1" 
     >


        <RadioButton 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:checked="true" 
            android:text="AAA" 
            android:button="@null"
            android:drawableLeft="@drawable/flag_icon"
            android:drawableRight="@android:drawable/btn_radio"
            android:drawablePadding="60dp"
            android:id="@+id/radio2"/>

        <RadioButton.../>
    </RadioGroup>

      

As you can see above, RadioButton

I have defined the following attributes for:

...
android:button="@null"
 android:drawableLeft="@drawable/flag_icon"
 android:drawableRight="@android:drawable/btn_radio"
 ...

      

To button was on the right side of the button text . The left side of the button text is the flag icon.

To have spaces between the button text and the icon icon and the button icon, I use android:drawablePadding="60dp"

to place them.

However, with the above code, the space 60dp

is applied to both the left drawing (flag icon) and the right drawable (toggle), which ends with radiotext in the middle between the two drawings.

I would like to have the radio button text and the left drawable (flag icon) have less space between them, and the button text and right drawable (radio button) have more space between them. How do I determine the different spaces for left drawing and right rotation of a radio button?

+3


source to share


3 answers


Just check it out:  



            <RadioButton
                android:id="@+id/radio0"
                style="@style/my_recording_title_text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:button="@null"
                android:checked="true"
                android:drawableRight="@drawable/presets_sel"
                android:padding="12dp"
                android:text="Play with EarPhones" />

            <View
                android:layout_width="fill_parent"
                android:layout_height="3dp"
                android:background="@drawable/line" />

            <RadioButton
                android:id="@+id/radio1"
                style="@style/my_recording_title_text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:button="@null"
                android:drawableRight="@drawable/presets_sel"
                android:padding="12dp"
                android:text="Play with internal speakers" />
        </RadioGroup>

      

+4


source


try this xml file or add property android: gravity = "center_horizontal | center_vertical" or android: gravity = "center" in your strong> radio and removepadding



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >   

    <RadioGroup
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/logo"
            android:button="@null"            
            android:drawableRight="@drawable/ic_launcher"
            android:gravity="center_horizontal|center_vertical"

            android:text="RadioButton" />
    </RadioGroup>

</LinearLayout>

      

0


source


This kind of thing happens a lot. And the sad truth is that the limitations of using RadioGroup with RadioButtons severely limit your ability to make your layouts correct.

I posted a very detailed solution here that includes dropping RadioGroups. I know this seems like a lot of work, but the code is very simple. Until RadioGroups are better implemented, this is the best solution I have found.

Good luck!

0


source







All Articles