[英]Distance between two radiobutton (horizontal radio group)
我想设置两个单选按钮之间的距离。
喜欢
我怎么能做到这一点? 我的代码就像
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView_your_order"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Delivery" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PickUp" />
</RadioGroup>
</LinearLayout>
上面的代码输出如下图所示
您可以通过以下方式实现此结果:使用 layout_weigth和匹配的单选组填充屏幕
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView_your_order"
android:orientation="horizontal">
<RadioButton
android:layout_weight="1"
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Delivery" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PickUp" />
</RadioGroup>
或者
甚至添加一个虚拟视图,将单选按钮推到左端和右端,如下所示:
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView_your_order"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Delivery" />
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RadioButton
android:gravity="end"
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PickUp" />
</RadioGroup>
在您希望它正确的 RadioButton 的 xml 中尝试android:gravity="right"
。 这应该是你想要的。
我在将代码更改为此代码后完成了。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/SkyBlue"
android:orientation="vertical"
android:padding="8dp" >
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView_your_order"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Delivery" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PickUp" />
</RadioGroup>
</LinearLayout>
只需在第一个单选按钮中更改布局宽度,Put : android:layout_width = "200dp"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.