12

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?

fcdt
  • 2,371
  • 5
  • 14
  • 26

2 Answers2

11

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

melkoth
  • 178
  • 7
3

Try using marginTop instead of padding. I would also reccoment using a style for that instead of setting the value manually to each item.

Lamorak
  • 10,957
  • 9
  • 43
  • 57