简体   繁体   English

RadioButtons的有效布局参数

[英]Valid layout params for RadioButtons

What layout parameter could I use to make my RadioButtons layout_alignParentStart and Below a View? 我可以使用什么布局参数来使RadioButtons layout_alignParentStart和“在视图下方”? In Android studio, doing this creates an error. 在Android Studio中,这样做会产生错误。 Or is there an attribute of some sort I could add to the RadioGroup? 还是可以添加到RadioGroup的某种属性?

here is the code: 这是代码:

   <RadioGroup
          android:layout_width="wrap_content"
          android:layout_height="wrap_content">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_button"
        android:id="@+id/radioButton"
        android:layout_below="@+id/text7"
        android:layout_alignParentStart="true"
        android:textSize="12sp"
        android:textColor="#000000"
        android:onClick="onRadioButtonClicked"/>
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_button2"
        android:id="@+id/radioButton2"
        android:layout_below="@+id/radioButton"
        android:layout_alignParentStart="true"
        android:textSize="12sp"
        android:textColor="#000000"
        android:onClick="onRadioButtonClicked"/>
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_button3"
        android:id="@+id/radioButton3"
        android:layout_below="@+id/radioButton2"
        android:layout_alignParentStart="true"
        android:textSize="12sp"
        android:textColor="#000000"
        android:onClick="onRadioButtonClicked"/>

Here's the deal: RadioGroup extends LinearLayout , and that means that RadioGroup wants all the radio buttons to be in a line, either horizontal or vertical. 这是要解决的问题: RadioGroup扩展了LinearLayout ,这意味着RadioGroup希望所有单选按钮都在水平或垂直线上。

If you need radio buttons in a grid or other non-linear layout, you can use something like RelativeLayout as a parent, but then you will have to listen to each one of the radio buttons directly and code the logic that turns the previous one off when the next one is selected. 如果您需要网格或其他非线性布局中的单选按钮,则可以使用诸如RelativeLayout类的父按钮,但是您将必须直接收听每个单选按钮,并编写逻辑以关闭前一个按钮当选择下一个时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM