det*_*ego 17 android gravity radio-group orientation radio-button
我使用TableLayout和TableRows作为我的主要活动.
TableLayout内部是一个Radio Group,在活动中包含2个Radio Buttons(Radio Group在表行内).我希望能够将最右边的单选按钮对齐到右边缘屏幕,因此"间隙"位于左侧单选按钮和右侧按钮之间(而不是右侧单选按钮之后).即
所以没有
| (x)(x)间隙|
我将
| |(x)gap(x)|
其中(x)是单选按钮和| 是屏幕的边缘
我可以使用重力(center_horizontal)将两个按钮放在中间(即| gap(x)(x)间隙|)但是我似乎无法按照我之前所说的方式将它们分开
Luc*_*ucy 32
所有你需要在屏幕上水平均匀地分隔任意数量的按钮:
android:orientation="horizontal"&
android:layout_width="fill_parent"android:layout_weight="1",除了最右边的按钮(使其在屏幕的右边缘排成一行)!
这花了我几个小时才弄明白.
以下是一些示例代码,其中包含两个文本标签以及屏幕的左右边缘,用于调查应用.
<RadioGroup
android:id="@+id/radio_group"
android:orientation="horizontal"
android:layout_below="@id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
>
<RadioButton
android:id="@+id/strong_disagree_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1"
/>
<RadioButton
android:id="@+id/disagree_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/disagree"
/>
<RadioButton
android:id="@+id/neutral_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/neutral"
/>
<RadioButton
android:id="@+id/agree_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/agree"
/>
<RadioButton
android:id="@+id/strong_agree_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
/>
</RadioGroup>
<TextView
android:id="@+id/disagree_label"
android:text="@string/strongly_disagree_txt"
android:layout_below="@id/radio_group"
style="@style/TextAppearance"
android:visibility="gone"
/>
<TextView
android:id="@+id/agree_label"
android:text="@string/strongly_agree_txt"
android:layout_below="@id/radio_group"
android:layout_alignParentRight="true"
style="@style/TextAppearance"
android:layout_width="wrap_content"
android:visibility="gone"
/>
Run Code Online (Sandbox Code Playgroud)
小智 9
找到了解决方案.重量和重力的组合,并删除边距.无线电组可以具有layout_width ="fill_parent".每个单选按钮应该有layout_weight ="1",但是仍然必须指定每个单选按钮的layout_width以覆盖默认的"37",我猜这是默认的单选按钮图像宽度.
<RadioGroup android:id="@+id/overall"
android:layout_width="fill_parent" android:layout_height="80dp"
android:gravity="center"
android:orientation="horizontal">
Run Code Online (Sandbox Code Playgroud)
第一个按钮应该有:
android:layout_weight="1"
android:layout_gravity="center|left"
Run Code Online (Sandbox Code Playgroud)
最后一个按钮应该有:
android:layout_gravity="center|right"
Run Code Online (Sandbox Code Playgroud)
注意:所有按钮都设置了layout_gravioty,但最右边的按钮没有layout_weight设置!
小智 0
您找到解决方案了吗?我的中间解决方案可能会有所帮助,但这对我来说并不是完整的情况。我已经能够通过设置特定宽度来做到这一点,但这不允许视图调整大小以适应屏幕宽度:
<RelativeLayout
android:id="@+id/overall_layout"
android:layout_width="290dp" android:layout_height="wrap_content">
<RadioGroup android:id="@+id/overall"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton android:id="@+id/overall_1" android:tag="1"
android:button="@drawable/radio_1"
android:layout_width="50dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"></RadioButton>
<RadioButton android:id="@+id/overall_2" android:tag="2"
android:button="@drawable/radio_2"
android:layout_width="50dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"></RadioButton>
<RadioButton android:id="@+id/overall_3" android:tag="3"
android:button="@drawable/radio_3"
android:layout_width="50dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"></RadioButton>
<RadioButton android:id="@+id/overall_4" android:tag="4"
android:button="@drawable/radio_4"
android:layout_width="50dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"></RadioButton>
<RadioButton android:id="@+id/overall_5" android:tag="5"
android:button="@drawable/radio_5"
android:layout_width="50dp"
android:layout_height="wrap_content"></RadioButton>
</RadioGroup>
<TextView android:text="left" android:id="@+id/left"
android:layout_below="@id/overall"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="right" android:id="@+id/right"
android:layout_below="@id/overall"
android:layout_alignParentRight="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
请注意,最后一个按钮上没有边距。
我试图在一个单选按钮组中有 5 个自定义按钮,第一个左对齐,最后一个右对齐。这些按钮的宽度正好是 50 像素,我不希望任何文本与这些按钮单独关联。下面的 2 个文本在相对布局中左对齐和右对齐。使用“layout_gravity”没有任何效果,“layout_weight”会在每个按钮的右侧添加填充,这会导致最右侧的按钮不再对齐。
这很令人费解。
| 归档时间: |
|
| 查看次数: |
32216 次 |
| 最近记录: |