Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide spacing between android Radio Buttons of Vertical orientation

I got a scenario where I need to provide spacing between radio buttons arranged vertically.
The below is my Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:paddingLeft="20dp"
    android:paddingStart="20dp"
    android:paddingRight="20dp"
    android:paddingEnd="20dp"
    >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="My text view"
        android:textSize="20dp"
        android:textColor="#000000"
        android:gravity="center_vertical"
        android:background="@drawable/roundedlabel"
        />
    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="152dp"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        >
        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="text view1"
            android:textSize="20dp"
            android:paddingTop="10dp" 
            />
        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="text view2"
            />
        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="text view3" 
            />
        <RadioButton
            android:id="@+id/radio3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="text v4iew" 
            />
    </RadioGroup>
</LinearLayout>

I tried to put android:paddingTop="10dp" for each of the radio buttons which takes the text to bottom, but the radio buttons remain on the same position.
Can anyone help me how to provide spacing between radio buttons arranged in vertical orientation?

like image 244
Android_programmer_office Avatar asked May 11 '15 19:05

Android_programmer_office


People also ask

How do you change a radio group from horizontal to vertical?

Drag a radio list widget to your screen, go to the Properties tab and select 'Orientation' -> Horizontal.

What are the methods of radio button in android?

RadioButton is a two states button which is either checked or unchecked. If a single radio button is unchecked, we can click it to make checked radio button. Once a radio button is checked, it cannot be marked as unchecked by user. RadioButton is generally used with RadioGroup.

How to use RadioGroup in android studio?

To create each radio button option, create a RadioButton in your layout. However, because radio buttons are mutually exclusive, you must group them together inside a RadioGroup . By grouping them together, the system ensures that only one radio button can be selected at a time.

How do I create a horizontal radio button?

To make a horizontal radio button set, add the data-type="horizontal" to the fieldset . The framework will float the labels so they sit side-by-side on a line, hide the radio button icons and only round the left and right edges of the group.


1 Answers

Try using the layout_margin attribute, it works similarly to padding, but may have the effect you want. You can use simply android:layout_margin="20dp" or you can set individual sides, like you can for padding (ex: android:layout_marginLeft="20dp").

like image 151
melkoth Avatar answered Oct 02 '22 01:10

melkoth