如何在 android 垂直方向的单选按钮之间提供间距
How to provide spacing between android Radio Buttons of Vertical orientation
我有一个场景需要在垂直排列的单选按钮之间提供间距。
下面是我的布局:
<?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>
我尝试为每个将文本置于底部的单选按钮放置 android:paddingTop="10dp"
,但单选按钮保持在同一位置。
任何人都可以帮助我如何提供垂直方向排列的单选按钮之间的间距吗?
尝试使用 marginTop
而不是 padding
。我还建议为此使用一种样式,而不是手动为每个项目设置值。
尝试使用 layout_margin 属性,它的工作方式与填充类似,但可能会达到您想要的效果。您可以简单地使用 android:layout_margin="20dp" 或者您可以设置单独的边,就像填充一样(例如:android:layout_marginLeft="20dp")。
我有一个场景需要在垂直排列的单选按钮之间提供间距。
下面是我的布局:
<?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>
我尝试为每个将文本置于底部的单选按钮放置 android:paddingTop="10dp"
,但单选按钮保持在同一位置。
任何人都可以帮助我如何提供垂直方向排列的单选按钮之间的间距吗?
尝试使用 marginTop
而不是 padding
。我还建议为此使用一种样式,而不是手动为每个项目设置值。
尝试使用 layout_margin 属性,它的工作方式与填充类似,但可能会达到您想要的效果。您可以简单地使用 android:layout_margin="20dp" 或者您可以设置单独的边,就像填充一样(例如:android:layout_marginLeft="20dp")。