سؤال

I'm Developing an android app in which the login activity contains radio button for the field department and years of experience. And I've designed my login activity in Relative layout.So now i wanted to RadioGroup the radiobuttons without changing the alignment. Please Help me ! Thanks in Advance !

`

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="@string/reg_view"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText2"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="59dp"
    android:ems="10"
    android:hint="@string/firstname"
    android:inputType="textPersonName"
    android:text="@string/edit_name" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/editText1"
    android:ems="10"
    android:hint="@string/lastname"
    android:inputType="textPersonName"
    android:text="@string/edit_name" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignLeft="@+id/editText1"
    android:layout_marginBottom="35dp"
    android:text="@string/name_view"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<RadioButton
    android:id="@+id/radioButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView4"
    android:layout_alignRight="@+id/textView1"
    android:text="@string/teamleader_radio" />
<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView4"
    android:layout_below="@+id/textView2"
    android:checked="true"
    android:text="@string/manager_radio" />
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/textView5"
    android:text="@string/Registration_proceed" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/radioButton1"
    android:layout_centerHorizontal="true"
    android:text="@string/years_view"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<RadioButton
    android:id="@+id/radioButton3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView4"
    android:layout_below="@+id/textView4"
    android:text="@string/years_check" />

<RadioButton
    android:id="@+id/radioButton4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/radioButton3"
    android:layout_alignBottom="@+id/radioButton3"
    android:layout_centerHorizontal="true"
    android:text="@string/years1_check" />

<RadioButton
    android:id="@+id/radioButton5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/radioButton4"
    android:layout_alignBottom="@+id/radioButton4"
    android:layout_alignParentRight="true"
    android:text="@string/years3_check" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/radioButton3"
    android:layout_toLeftOf="@+id/radioButton4"
    android:text="@string/dept_view"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/radioButton1"
    android:layout_below="@+id/editText2"
    android:text="@string/desig_view"
    android:textAppearance="?android:attr/textAppearanceMedium" />

`

هل كانت مفيدة؟

المحلول

You can use the <RadioGroup> to group the Radio buttons like this;

<RadioGroup 
    android:id="@+id/radioGroup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <RadioButton
        android:id="@+id/Red"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/red"
        android:textColor="@android:color/holo_red_dark" 
        android:onClick="onRadioButtonClicked" />

    <RadioButton
        android:id="@+id/Green"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/green"
        android:textColor="@android:color/holo_green_dark"
        android:onClick="onRadioButtonClicked"/>

    <RadioButton
        android:id="@+id/Blue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/blue"
        android:textColor="@android:color/holo_blue_dark"
        android:onClick="onRadioButtonClicked"/>

</RadioGroup>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top