2016-09-28 2 views
1

frage ich möchte wissen, wie wir Radio Group in Android, wie dieses Bild entwerfenStil Radio Group Android

My Radio Button "My Style"

Ich bin Design XML wie folgt aus:

<RadioGroup 
     android:layout_below="@+id/btnGroup" 

     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <RadioButton 
       android:id="@+id/rdiEasy" 
       android:text="EASY" 
       android:layout_alignParentLeft="true" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <RadioButton 
       android:id="@+id/rdiMedium" 
       android:text="MEDIUM" 
       android:layout_marginRight="8dp" 
       android:layout_alignParentRight="true" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <RadioButton 
       android:id="@+id/rdiHard" 
       android:text="HARD" 
       android:layout_alignParentLeft="true" 

       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <RadioButton 
       android:id="@+id/rdiHardest" 
       android:text="HARDEST" 
       android:layout_alignParentRight="true" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </RelativeLayout> 
    </RadioGroup> 

Ich verwende RadioButtonGroup wrap 2 RelativeLayout, jedes RelativeLayout enthält zwei Radio Button. Aber mit diesem Entwurf kann ich nicht nur einen Radioknopf wählen, kann immer noch Radioknopf wählen. So kann mir jeder helfen, Radio Button mit diesem Design zu gestalten, aber nur eine Option auswählen.

+0

Verwendung zweier Linearlayout nur eine oder mehrere ausgewählt (horizontal) innerhalb von LinearLayout mit Ausrichtung vertikal statt relativem Layout. –

+0

Zu Ihrer Information RadioGroup sollte nur RadioButton enthalten –

+0

Danke für die Antwort, ich meine, ich habe proplem mit Wahlmodus von RadioGroup! Mit meinem Code kann ich dieses Design implementieren, aber kann nicht nur eine Option wählen (Radio Button Group funktioniert nicht) – EddyLee

Antwort

-1

ich denke, das für Sie arbeiten wird

https://gist.github.com/ishitcno1/9544243

+0

Ich kann diesen Entwurf implementieren, ich habe nur proplem mit RadioButtonGroup. Ich kann nicht nur eine Option wählen. Kann immer noch wählen Multi-Option – EddyLee

+0

Hey EddyLee Ich änderte meinen Code & es funktioniert mir bitte überprüfen Sie es für die gleiche Jetzt wird es nur ein Radio wählen –

+0

Ja, ich sah Ihren Code, aber immer noch proplem: Sie haben zwei RadioButtonGroup; Ich brauche nur eine Radiobutton-Gruppe, weil ich nur 1/4 Option wählen möchte – EddyLee

0

Verwenden Sie diesen Code, um es perfekt zu arbeiten.

<RelativeLayout 
    android:id="@+id/rl1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true"> 

    <RadioGroup 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:orientation="horizontal" 
     android:transitionGroup="true"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingLeft="30dp"> 

      <RadioButton 
       android:id="@+id/rdiEasy" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Easy" /> 

      <RadioButton 
       android:id="@+id/rdiHard" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hard" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingLeft="30dp"> 

      <RadioButton 
       android:id="@+id/rdiMedium" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@+id/rdiEasy" 
       android:text="Medium" /> 

      <RadioButton 
       android:id="@+id/rdiHardest" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@+id/rdiHard" 
       android:text="Hardest" /> 

     </LinearLayout> 
    </RadioGroup> 
</RelativeLayout> 
+0

Mit Ihrem Code haben noch proplem. Ich kann immer noch wählen beide 4 Option von Radio – EddyLee

+0

hier bekommen Problem aufgrund der linearen Layout.Ich werde Sie bald aktualisieren. –

0

diesen Code Versuchen ohne Layouts innen mit radiogroup.and versuchen, das gewünschte Muster zu erreichen, indem die Schwerkraft, wie folgt aus und prüfen, ob Optionsfeld

<RadioGroup 
    android:id="@+id/radioGroup" 
    android:layout_width="500dp" 
    android:layout_height="250dp" 
    android:layout_weight=".07" 
    android:gravity="center"> 


    <RadioButton 
     android:id="@+id/radioButton2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left|top" 
     android:layout_marginLeft="5dp" 
     android:text="New RadioButton" /> 

    <RadioButton 
     android:id="@+id/radioButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right|top" 
     android:layout_marginRight="5dp" 
     android:text="New RadioButton" /> 

    <RadioButton 
     android:id="@+id/radioButton4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|left" 
     android:layout_marginLeft="5dp" 
     android:text="New RadioButton" /> 

    <RadioButton 
     android:id="@+id/radioButton3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right" 
     android:layout_marginRight="5dp" 
     android:text="New RadioButton" /> 

</RadioGroup>