How to add margin between radiobutton ant it's drawable?
Asked Answered
Z

5

13

This my current layout:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#F5F5DC"
    >

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

 <RadioGroup
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  >
  <RadioButton android:id="@+id/radio_red"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
       android:drawableLeft="@drawable/flag_dk"
       android:textColor="#000000"
       android:layout_gravity="center_horizontal"
       android:drawablePadding="10dip"
      android:text="Danish" />
  <RadioButton android:id="@+id/radio_blue"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:drawableLeft="@drawable/flag_en"
      android:layout_gravity="center_horizontal"
      android:layout_marginTop="5dip"

      android:drawablePadding="10dip"
      android:textColor="#000000"
      android:text="English" />
</RadioGroup>


</LinearLayout>
    </ScrollView>

I get this:

enter image description here

I would like to have some space (margin) between radiobutton an the flag (it's drawable). Is it even possible?

Zacheryzack answered 11/3, 2011 at 9:24 Comment(4)
If you don't mind having the flag to the right of text, then its position is easily adjustable with android:drawablePadding.Namely
Using drawableRight insted of drawableLeft makes no difference. Using this, there is no margin between radiobutton and text instead of between radiobutton and drawable.Zacheryzack
Uhm..seems like you are right; I had tested that in Eclipse using Graphical Layout, for Android 1.6 to 2.2, and there was a raisonnable margin between radiobutton and text, but seems like from 2.3 the space is tiny, like in your picture.Namely
@Zacheryzack try to remove layout_gravity and use layout_marginTop this approach worked for me.Mefford
M
8

You can do like the following:

    <android.support.v7.widget.AppCompatRadioButton
        android:layout_width="match_parent"
        android:layout_height="@dimen/view_size"
        android:button="@null"
        android:drawablePadding="100dp"
        android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
        android:text="label" />

enter image description here

Malkin answered 17/5, 2016 at 14:42 Comment(0)
J
4

In my case, where I have a custom drawable shape, adding android:paddingDrwable attribure did not work but adding android:paddingLeft="5dp" did.

Janessa answered 4/3, 2014 at 11:3 Comment(0)
T
3

Where you are setting the image and the text give blank spaces before it. for example: radiobutton.setText(" "+Text);.You will see the desired output.

Tobiastobie answered 28/4, 2012 at 9:30 Comment(0)
E
2

I don't think it is possible to add space between the image and the radio button using the android apis. However, the answer to your question I think is to add some space in the image itself.

Evilminded answered 18/6, 2011 at 7:33 Comment(0)
S
1

Use Relative Layout instead of Linear Layout it gives android:layout_margingleft & android:layout_margingRight to drop your radio buton & Images as well.

Also give android:padding="10dip"

Try it it will definitely work!!!!

Savor answered 16/1, 2012 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.