我想在文本下方排列单选按钮,但我做不到。我使用过 android:layout_marginLeft="20dp"但它仅适用于特定设备而不适用于所有设备。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ff0000"
android:gravity="center"
android:text="red" />
<TextView
android:id="@+id/txt2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#00ff00"
android:gravity="center"
android:text="green" />
<TextView
android:id="@+id/txt3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#0000ff"
android:gravity="center"
android:text="blue" />
</LinearLayout>
<RadioGroup
android:id="@+id/rg_rgrp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<RadioButton
android:id="@+id/rbtn_red"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center" />
<RadioButton
android:id="@+id/rbtn_green"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" />
<RadioButton
android:id="@+id/rbtn_blue"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" />
</RadioGroup>
我同时使用了 Gravity 和 layout_gravity,但它适用于文本而不适用于单选按钮。
最佳答案
您的 RadioGroup
应该如下所示。无需代码。
<RadioGroup
android:id="@+id/rg_rgrp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioButton
android:id="@+id/rbtn_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="2" />
<RadioButton
android:id="@+id/rbtn_green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="2" />
<RadioButton
android:id="@+id/rbtn_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</RadioGroup>
关于android - 将单选按钮排列在文本正下方,并完美地位于所有 Android 设备的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19490795/