管理布局内的水平取向的RadioGroup中取向、布局、水平、RadioGroup

2023-09-05 07:13:48 作者:青春无敌美少女

我使用的是TableLayout与TableRows作为我的主要活动。

I am using a TableLayout with TableRows as my main activity.

在TableLayout是一个单选按钮组包含的活动(无线电集团作为一个表行内)内2个单选按钮。我希望能够以对准最右边的单选按钮的右边缘屏幕,因此,缺口是左单选按钮和右按钮(而不是正确的单选按钮之后)之间。即。

Inside the TableLayout is a Radio Group containing 2 Radio Buttons inside the activity (the Radio Group being inside a table row). I want to be able to align the rightmost radio button to the right edge screen, so the "gap" is between the left radio button and right button (instead of after the right radio button). i.e.

因此​​,而不是有 | (X)(X)的差距| 我将有 |(x)的间隙(X)|

So instead of having | (x) (x) gap | I will have |(x) gap (x)|

其中(x)是单选按钮和|是在屏幕的边缘

where (x) are the Radio Buttons and | are the edges of the screen

我可以用重力(center_horizo​​ntal)既把按钮在中间(即|间隙(X)(X)的差距|),但是我不能似乎能够分裂他们的方式,我想以前一样说:

I can use gravity (center_horizontal) to put both the buttons in the middle (i.e. | gap (x)(x) gap|) however I can't seem to be able to split them the way I want as said before

推荐答案

您只需要均匀的空间水平在屏幕上的按钮任意数量的:

All you need to evenly space an arbitrary number of buttons horizontally across the screen:

RadioGroup中必须有 安卓方向=横向&放大器; 机器人:layout_width =FILL_PARENT 在每个单选按钮必须具有 的android:layout_weight =1,除了 最右边的按钮(使它 对的右边缘排队 屏幕)! RadioGroup has to have android:orientation="horizontal" & android:layout_width="fill_parent" Each radio button has to have android:layout_weight="1", except the rightmost button (to make it line up on the right edge of the screen)!

这花了我时间才能体现出来。

This took me hours to figure out.

下面是一些例子code,有两个文本标签奖金的权利和屏幕的左边缘,对于调查程序。

Here is some example code, with a bonus of two text labels and the right and left edges of the screen, for a survey app.

<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"
    />