0

What layout parameter could I use to make my RadioButtonslayout_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"/>
Nahidaa
  • 53
  • 6
  • What is the parent view? Layout_alignParentStart refers to the parent view. – FishStix Aug 08 '16 at 20:57
  • RadioGroup is a subclass of LinearLayout and the orientation is set to vertical. What are you trying to do? The RadioButtons should be already aligned at the start for you. – ono Aug 08 '16 at 21:01
  • @FishStix the parentview is relative layout – Nahidaa Aug 08 '16 at 21:04
  • @ono Iif im using a relative layout do i still need to have the buttons inside a radio group? sorry i am a beginner. – Nahidaa Aug 08 '16 at 21:06

1 Answers1

3

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.

kris larson
  • 30,387
  • 5
  • 62
  • 74