Add margin between a RadioButton and its label in Android?

android radio button margin programmatically
add padding to radio button programmatically android
radio button add margin programmatically
add margin to radio button
android radio button remove padding
android radiogroup space between buttons
custom radio button android
radio button label space

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 scrunched.

<RadioButton android:id="@+id/rb1"
    android:text="My Text"/>

I've tried a couple of things:

  1. Specifying margin and padding seem to add space around the entire element (button and text, together). That makes sense, but doesn't do what I need.

  2. Creating a custom drawable via XML specifying images for the checked and unchecked states, then adding a few extra pixels to the right side of each image. This should work, but now you are stepping outside the default UI. (Not the end of the world, but not ideal)

  3. Add extra whitespace to the beginning of each label. Android seems to trim a leading space character, as in " My String", but specifying unicode U+00A0, as in "\u00A0My String" does the trick. This works, but it seems kinda dirty.

Any better solutions?

For anyone reading this now, the accepted answer will lead to some layout problems on newer APIs causing too much padding.

On API <= 16 you can set paddingLeft 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 paddingLeft (or paddingStart) is in relation to the radio button drawable. Same applies to the about a patch nine. To better illustrate padding differences see the attached screenshot.

If you dig through the code you will find a new method in API 17 called getHorizontalOffsetForDrawables. This method is called when calculating the left padding for a radio button(hence the additional space illustrated in the picture).

TL;DR Just use paddingLeft if your minSdkVersion is >= 17. If you support API <= 16, you should have radio button style for the min SDK you are supporting and another style for API 17+.

[] Add option for padding , In this tutorial we will learn about Margin and Padding attributes which can be used to RadioGroup, RadioButton and CheckBox � AutoCompleteTextView in Android There is always a confusion between the padding and margin attribute when you Here, its content will be the different views that it holds like TextView, � Android :: Add Margin Between A Radiobutton Its Label In Phone? Jan 25, 2010 Is it possible to add a little bit of space between a RadioButton and the label while still using Android's built-in components?

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

Margin and Padding in an Android View, In this tutorial, you will learn how to add Radio Buttons to a layout. Radio Buttons are used Click on the default Hello World TextView to select it. In the properties area Android Studio 3 palette showing the RadioGroup widget. Before dragging a This will create a little bit of space between the two controls: Space added� The Margin property represents the distance between an element and its adjacent elements, and is used to control the element's rendering position, and the rendering position of its neighbors. Margin values can be specified on layout and view classes. The Padding property represents the distance between an element and its child elements, and is

Android Radio Buttons and Radio Groups, 问题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� RadioButton & RadioGroup Tutorial With Example In Android Studio. In Android, RadioButton are mainly used together in a RadioGroup.In RadioGroup checking the one radio button out of several radio button added in it will automatically unchecked all the others.

Add margin between a radiobutton its label by paddingLeft:


Just set your custom padding.

RadioButton's xml property.

    android:textSize="12sp" />


Add margin between a RadioButton and its label in Android?, To define the click event handler for a button, add the android:onClick attribute to the <RadioButton> element in your XML layout. The value for� A button consists of text or an icon (or both text and an icon) that communicates what action occurs when the user touches it. Depending on whether you want a button with text, an icon, or both, you can create the button in your layout in three ways:

Use the following XML attributes. It worked for me

For API <= 16 use


For API >= 17 use



        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:

    android:text="New RadioButton" />

Radio Buttons, Here, padding is the space between the content and the boundaries of the Step 3: And last add this RadioButton control to the form using Add() method. Adding this label to the form. this .Controls.Add(l);. // Creating and setting the. How do I change the spacing between the radio button and the "1+" text? I'd like the text to be closer to the radio button, but the browser is inserting a certain amount of undefined padding between the two elements.

How to set the Padding of the RadioButton in C#?, If you want a form with labels on the left and fields on the right, you in a RadioGroup), you need a container just to have a root element in which to the android:orientation property to your LinearLayout element in your XML layout, and edges, while adding margins increases the empty space between the edges and. In the Android screenshot, the Shrink value for the second Label is set to 0, and that Label is displayed in its full width. Also, the fourth Label is given a Shrink value greater than one, and it has shrunk.

Working with Containers, Note:<RadioButton> is auto-inflated as < Radio buttons support content labeling for accessibility and are readable by most Changes in the states of one radio button can affect other buttons in the group. be collapsed, consider using a dropdown menu because it uses less space. Recyclerview is works just like listview but more well organised, felexible to customize and optimize to work and in rendering the view of large data set. To automatically switch between views, add the autoStart tag and set its value to true. 10 Jun 2020 Sets the relative start margin. JS · iOS · Android · v8. 4 Set the Button onClickListener.

Material selection controls: Radio buttons, Visualforce � Lightning � Heroku � Android � iOS Adjust whitespace by applying horizontal and vertical padding helpers. Classes prefixed in slds-m- are used for adding margin; The directions available for the spacing classes are The tables below show how the values change between the Comfy and Compact settings. Extract the string resource for the android:text attribute value to create and entry for it called name_label_text in strings.xml.; Add an EditText element. To use the visual layout editor, drag a Plain Text element from the Palette pane to a position next to the name_label TextView.

  • api 17 is android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
  • The best way to do this is with a "values-v17" directory; put your API 17+ dimension in a resources xml there and the standard one for 16 and below in just plain "values".
  • Amazing how Google developers / management are treating us usual devs. They do whatever they want, whenever they want. Consistency and integrity mean nothing to them.
  • This works, and 50dip is needed to cover the width of the default drawable. At first I used 20dip and the text moved left! That's because the anchoring point is not the right edge of the drawable; it is the left edge of the drawable.
  • The best answer! You can also set android:background="@null" and will look as you stated with no padding.
  • when i'm setting android:button="@null" , the radio button is not getting checked(clicked). Im i doing something wrong. please help…
  • @Shirish this solution has nothing to do with your button not being clicked. I just implemented it and it is clicked.
  • Thanks for the solution!
  • Hm. Gave it a try and it doesn't seem to have any effect in this situation. Thanks for the suggestion, it certainly sounds right from the description: "The padding between the drawables and the text".
  • i was looking exactly for this... helped me a lot
  • @dimen/10dp bad practise
  • Consider adding some comments to explain how this solve the problem ;)
  • @Mark Buikema, Absolutely it is not label, but it does works like label here! If you want click labels, you can add click listeners to TextViews. My point is, does we need to implement layout for e-v-e-r-y version of android os? I think, no.