简体   繁体   中英

Valid layout params for RadioButtons

What layout parameter could I use to make my RadioButtons layout_alignParentStart and Below a View? In Android studio, doing this creates an error. Or is there an attribute of some sort I could add to the 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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