Add margin between a RadioButton and its label in Android?

后端 未结 18 1478
春和景丽
春和景丽 2020-12-02 10:43

Is it possible to add a little bit of space between a RadioButton and the label while still using Android\'s built-in components? By default the text looks a little scrunche

相关标签:
18条回答
  • 2020-12-02 11:39

    for me works:

    <?xml version="1.0" encoding="utf-8"?>
        <selector xmlns:android="http://schemas.android.com/apk/res/android">
            <item android:state_checked="true">
                <layer-list>
                    <item android:right="5dp">
                        <shape android:paddingLeft="5dp" android:shape="oval">
                         <size android:width="20dp" android:height="20dp" />
                         <solid android:color="@color/blue" />
                </shape>
            </item>
        </layer-list>
    </item>
    <item android:paddingLeft="5dp" android:state_checked="false">
        <layer-list>
            <item android:right="5dp">
                <shape android:paddingLeft="5dp" android:shape="oval">
                    <size android:width="20dp" android:height="20dp" />
                    <solid android:color="@color/grey" />
                    </shape>
                </item>
            </layer-list>
        </item>
    </selector>
    
    0 讨论(0)
  • 2020-12-02 11:40

    Can't try this right now to verify, but have you tried to see if the attribute android:drawablePadding does what you need?

    0 讨论(0)
  • 2020-12-02 11:43

    You can this code on your XML file

    <RadioButton
    android:id="@+id/rButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawablePadding="50dp"
    android:paddingLeft="10dip"
    android:text="@string/your_text" />
    

    or use this on Activity class

    radioButton.setPadding(12, 10, 0, 10);
    
    0 讨论(0)
  • 2020-12-02 11:45

    You could try using the gravity attribute of radio button .

    <RadioButton
                            android:id="@+id/rb_all"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:checked="true"
                            android:gravity="right|center_vertical"
                            android:padding="@dimen/padding_30dp"
                            android:text="@string/filter_inv_all"
                            android:textColor="@color/black"
                            android:textSize="@dimen/text_size_18" />
    

    This will align the text to the right most end . Check out the first radio in the image.

    0 讨论(0)
  • 2020-12-02 11:46

    Not sure if this will fix your problem, but have you tried Radio Button's "Padding left" property with a value of 50dip or more

    0 讨论(0)
  • 2020-12-02 11:46

    I have tried, "android:paddingLeft" will works. paddingLeft will only impact the text while keep the radio image stay at the original position.

    0 讨论(0)
提交回复
热议问题