androidandroid-layoutandroid-radiobutton

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?


Solution

  • 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").