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?
Drag a radio list widget to your screen, go to the Properties tab and select 'Orientation' -> Horizontal.
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.
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.
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.
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").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With