2017-05-13 2 views
0

Ich habe nur 2 radiobutton In XML-Datei Alles, was ich eine radiogroup auch hinzufügen müssen hinzufügen und setzen diese zwei Radio-Buttons in der radiogroup aber mit der gleichen Ansicht hier ist meine XML-DateiWie Radio Group, um diese XML-Datei

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:background="#FFFFFF" 
    android:layout_height="match_parent" 
    tools:context="mediaclub.app.paymob.GameeyaFragment"> 

    <de.hdodenhof.circleimageview.CircleImageView 
     android:id="@+id/profileImage" 
     android:layout_width="70dp" 
     android:layout_height="70dp" 
     android:layout_marginTop="28dp" 
     app:srcCompat="@android:drawable/sym_def_app_icon" 
     android:src="@mipmap/ic_launcher" 
     android:layout_alignParentTop="true" 
     app:civ_border_color="@color/dark" 
     android:layout_alignStart="@+id/amountEt" /> 

    <EditText 
     android:id="@+id/gam3eyaNmeET" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:hint="Gam3eya Name" 
     android:layout_alignTop="@+id/profileImage" 
     android:layout_toRightOf="@+id/profileImage" 
     android:layout_toEndOf="@+id/profileImage" 
     android:layout_marginTop="13dp" /> 

    <EditText 
     android:id="@+id/amountEt" 
     android:layout_width="330dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="39dp" 
     android:ems="10" 
     android:hint="Amount" 
     android:backgroundTint="#8F8E8F" 
     android:layout_below="@+id/uploadImgId" 
     android:layout_centerHorizontal="true"> 

     <requestFocus /> 
    </EditText> 

    <TextView 
     android:id="@+id/text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="EGP" 
     android:textSize="20dp" 
     android:textColor="#1A99C4" 
     android:layout_marginEnd="23dp" 
     android:layout_alignBaseline="@+id/amountEt" 
     android:layout_alignBottom="@+id/amountEt" 
     android:layout_alignEnd="@+id/amountEt" /> 

    <TextView 
     android:id="@+id/uploadImgId" 
     android:layout_width="wrap_content" 
     android:textSize="10dp" 
     android:layout_height="wrap_content" 
     android:textColor="#1A99C4" 
     android:text="Upload Image" 
     android:layout_below="@+id/profileImage" 
     android:layout_alignEnd="@+id/profileImage" 
     android:layout_marginEnd="17dp" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="75dp" 
     android:id="@+id/ll" 
     android:layout_weight="15" 
     android:layout_below="@+id/amountEt" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <RadioButton 
      android:id="@+id/monthlyRb" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:buttonTint="#1A99C4" 
      android:layout_marginLeft="60dp" 
      android:text="Monthly" 
      android:layout_weight="1" 
      android:layout_centerVertical="true" 
      android:layout_alignStart="@+id/amountEt" /> 

     <RadioButton 
      android:id="@+id/weeklyRadioBtn" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:buttonTint="#1A99C4" 
      android:layout_weight="1" 
      android:text="Weekly" 
      android:layout_alignTop="@+id/monthlyRb" /> 
    </LinearLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="75dp" 
     android:id="@+id/rl" 
     android:layout_weight="15" 
     android:layout_below="@+id/ll" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="15dp" 
      android:textColor="#000000" 
      android:text="Reminder" 
      android:layout_marginStart="56dp" 
      android:layout_alignBaseline="@+id/textView6" 
      android:layout_alignBottom="@+id/textView6" 
      android:layout_alignParentStart="true" /> 

     <Spinner 
      android:id="@+id/reminderSpinner1" 
      android:layout_width="45dp" 
      android:textAlignment="2" 
      android:layout_height="wrap_content" 
      android:layout_marginStart="15dp" 
      android:layout_alignTop="@+id/textView5" 
      android:layout_toEndOf="@+id/textView5" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Days" 
      android:textSize="15dp" 
      android:textColor="#000000" 
      android:layout_marginStart="12dp" 
      android:layout_centerVertical="true" 
      android:layout_toEndOf="@+id/reminderSpinner1" /> 
    </RelativeLayout> 

    <Button 
     android:id="@+id/nxtBtn" 
     android:layout_width="120dp" 
     android:layout_height="wrap_content" 
     android:background="@drawable/nextbtn" 
     android:layout_marginBottom="62dp" 
     android:textColor="#ffffff" 
     android:text="Next" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

leid, wenn irgend etwas nicht klar ist, hoffe ich, diese werde verständlich sein

Antwort

0

1.RadioGroup als Container von monthlyRb hinzufügen und weeklyRadioBtn. Verwenden Sie die Ausrichtung horizontal oder vertical nach Ihren Bedürfnissen.

2. Entfernen Sie redundante Attribute von RadioButtons.

Versuchen Sie folgendes:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="75dp" 
    android:id="@+id/ll" 
    android:layout_weight="15" 
    android:layout_below="@+id/amountEt" 
    android:orientation="horizontal"> 

    <RadioGroup 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <RadioButton 
      android:id="@+id/monthlyRb" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:buttonTint="#1A99C4" 
      android:layout_marginLeft="16dp" 
      android:text="Monthly" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:id="@+id/weeklyRadioBtn" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:buttonTint="#1A99C4" 
      android:layout_weight="1" 
      android:text="Weekly" /> 
    </RadioGroup> 

</LinearLayout> 
+0

Dank für meine Antwort zu akzeptieren. Wenn meine Antwort nützlich erscheint, können Sie eine positive Bewertung abgeben. – FAT

0

Ihre Radiobuttons in xml mit RadioGroup Wrap: Und gelten android:orientation="horizontal" in der RadioGroup

<LinearLayout 
     android:id="@+id/ll" 
     android:layout_width="match_parent" 
     android:layout_height="75dp" 
     android:gravity="center" 
     android:layout_below="@+id/amountEt" 
     android:layout_weight="15" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <RadioGroup 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <RadioButton 
       android:id="@+id/monthlyRb" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_alignStart="@+id/amountEt" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="60dp" 
       android:layout_weight="1" 
       android:buttonTint="#1A99C4" 
       android:text="Monthly" /> 

      <RadioButton 
       android:id="@+id/weeklyRadioBtn" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@+id/monthlyRb" 
       android:layout_weight="1" 
       android:buttonTint="#1A99C4" 
       android:text="Weekly" /> 
     </RadioGroup> 
    </LinearLayout> 
0

XML-Datei:

<RadioGroup 
    android:layout_width="fill_parent" 
    android:layout_height="90dp" 
    android:weightSum="1" 
    android:id="@+id/radioGroup"> 

    <RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="55dp" 
    android:text="Male" 
    android:id="@+id/radioButton" 
    android:layout_gravity="center_horizontal" 
    android:checked="false" 
    android:textSize="25dp" /> 

    <RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Female" 
    android:id="@+id/radioButton2" 
    android:layout_gravity="center_horizontal" 
    android:checked="false" 
    android:textSize="25dp" 
    android:layout_weight="0.13" /> 

Java-Klasse:

radioSexGroup=(RadioGroup)findViewById(R.id.radioGroup); 

    btnDisplay=(Button)findViewById(R.id.button); 

    btnDisplay.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     int selectedId=radioSexGroup.getCheckedRadioButtonId(); 
     radioSexButton=(RadioButton)findViewById(selectedId); 
     Toast.makeText(MainActivity.this,radioSexButton.getText(),Toast.LENGTH_SHORT).show(); 
    } 
    }); 
Verwandte Themen