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
Add margin between a radiobutton its label by paddingLeft:
android:paddingLeft="10dip"
Just set your custom padding.
RadioButton's xml property.
<RadioButton
android:id="@+id/radHighest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/YourImageResource"
android:drawablePadding="50dp"
android:paddingLeft="10dip"
android:text="@string/txt_my_text"
android:textSize="12sp" />
Done
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@null"
android:paddingLeft="20dp"
android:text="1"
android:textColor="@color/text2"
android:textSize="16sp"
android:textStyle="bold" />
i tried several ways and finished with this one working correctly on both emulator and devices:
<RadioButton
android:background="@android:color/transparent"
android:button="@null"
android:drawableLeft="@drawable/your_own_selector"
android:drawablePadding="@dimen/your_spacing" />
Create a style in style.xml like this
<style name="Button.Radio">
<item name="android:paddingLeft">@dimen/spacing_large</item>
<item name="android:textSize">16sp</item>
</style>
Put that style in radio button
<RadioButton
android:id="@+id/rb_guest_busy"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="@string/guest_is_waiting"
android:textSize="@dimen/font_size_3x_medium"
android:drawablePadding="@dimen/spacing_large"
android:textColor="@color/color_text_heading_dark"
style="@style/Button.Radio"/>
You can change any attribute same as button as it RadioButton indirectly inherits button.
Use the following XML attributes. It worked for me
For API <= 16 use
android:paddingLeft="16dp"
For API >= 17 use
android:paddingStart="@16dp"
Eg:
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/popularityRadioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:paddingEnd="@dimen/radio_button_text"
android:paddingLeft="@dimen/radio_button_text"
android:paddingRight="@dimen/radio_button_text"
android:paddingStart="@dimen/radio_button_text"
android:text="Popularity"
android:textSize="@dimen/sort_dialog_text_size"
android:theme="@style/AppTheme.RadioButton" />
Further More: drawablePadding
attribute doesn't work. It only works if you added a drawable in your radio button. For Eg:
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:button="@null"
android:drawableEnd="@android:drawable/btn_radio"
android:drawablePadding="56dp"
android:drawableRight="@android:drawable/btn_radio"
android:text="New RadioButton" />
I came here looking for an answer and the simplest way (after some thinking) was add spacing at the beginning of the label itself like so
<RadioGroup
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/btnChangeMode"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_below="@+id/view3"
android:gravity="center|left"
android:id="@+id/ledRadioGroup">
<RadioButton
android:button="@drawable/custom_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" On"
android:layout_marginRight="6dp"
android:id="@+id/ledon"
android:textColor="@color/white" />
<RadioButton
android:button="@drawable/custom_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Off"
android:layout_marginLeft="6dp"
android:id="@+id/ledoff"
android:textColor="@color/white" />