【问题标题】:RadioGroup with radiobuttons inside a relative android layout在相对 android 布局中带有单选按钮的 RadioGroup
【发布时间】:2011-04-26 14:23:13
【问题描述】:

我想创建一个简单的布局,如下所示:

(o) Radio button A
(o) Radio button B [textedit]
    [x] checkbox

为此,我创建了以下 layout.xml:

<RadioGroup 
    android:layout_above="@+id/RadioButton_Count" 
    android:id="@+id/RadioGroup01" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">
    <RadioButton 
        android:layout_height="wrap_content" 
        android:id="@+id/RadioButton_A" 
        android:text="Play forever" 
        android:checked="true" 
        android:layout_width="fill_parent" 
        android:textSize="20sp">
    </RadioButton>
    <RelativeLayout 
        android:id="@+id/RelativeLayout01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
        <RadioButton 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/RadioButton_B" 
            android:text="Count:" 
            android:textSize="20sp">
        </RadioButton>
        <EditText 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/EditText_NumCount" 
            android:inputType="number" 
            android:layout_toRightOf="@+id/RadioButton_B" 
            android:width="70sp" >
        </EditText>
        <CheckBox 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/CheckBox_StopCount" 
            android:text="Stop" 
            android:layout_below="@+id/RadioButton_B" 
            android:textSize="18sp">
        </CheckBox>
    </RelativeLayout>
</RadioGroup>

看起来不错,但问题是单选按钮之间没有连接,我的意思是它们可以同时打开。 我认为这是因为即使它们挂在同一个布局中,第二个也在另一个布局中:\ 有谁知道我怎样才能制作这种布局(主要是 [textedit] 就在 RadioButton B 的右边),同时使单选按钮也能正常工作? 非常感谢

【问题讨论】:

    标签: android user-interface layout radio-button


    【解决方案1】:

    首先要尝试的是在关闭最后一个 RadioButton 后立即关闭 RadioGroup,而不是在最后关闭。更好的解决方案是使用RelativeLayout 作为整体容器。接下来添加您的 RadioGroup 和两个按钮并关闭该组。相对于布局的其余部分添加其他元素。

    【讨论】:

      【解决方案2】:

      你根本做不到。我也试图做类似的事情并被卡住了。

      “RadioButtons 必须是 RadioGroup 的直接子级。” https://code.google.com/p/android/issues/detail?id=1214

      【讨论】:

        猜你喜欢
        • 2017-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-30
        • 1970-01-01
        • 2014-04-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多