2017-08-19 2 views
0

Wie der Titel sagt, muss ich den Text direkt unter der ToggleButton, die unter einer RadioGroup sind.TextView unter ToggleButton in RadioGroup

Current Display

Ich möchte den Status-Text jedem Kreis. Ich habe versucht mit der Kombination von usw. aber nicht geklappt.

Hier ist mein Layout Teil:

<LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:orientation="horizontal" 
     android:paddingBottom="10dp" 
     android:paddingLeft="10dp" 
     android:paddingTop="10dp"> 

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


      <ToggleButton 
       android:id="@+id/toggleOnlineStatus" 
       android:layout_width="50dp" 
       android:layout_height="wrap_content" 
       android:background="@drawable/style_toggle_button" 
       android:checked="true" 
       android:textOff="" 
       android:textOn="" /> 

      <TextView 
       android:id="@+id/tvOnline" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/toggleOnlineStatus" 
       android:layout_centerHorizontal="true" 
       android:text="Away" /> 

      <ToggleButton 
       android:id="@+id/toggleAwayStatus" 
       android:layout_width="50dp" 
       android:layout_height="wrap_content" 
       android:background="@drawable/style_toggle_button" 
       android:textOff="" 
       android:textOn="" /> 

      <TextView 
       android:id="@+id/tvAway" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center_horizontal" 
       android:text="Away" /> 

      <ToggleButton 
       android:id="@+id/toggleDNDStatus" 
       android:layout_width="50dp" 
       android:layout_height="wrap_content" 
       android:background="@drawable/style_toggle_button" 
       android:textOff="" 
       android:textOn="" /> 

      <TextView 
       android:id="@+id/tvDND" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="DND" /> 

      <ToggleButton 
       android:id="@+id/toggleXAStatus" 
       android:layout_width="50dp" 
       android:layout_height="wrap_content" 
       android:background="@drawable/style_toggle_button" 
       android:textOff="" 
       android:textOn="" /> 

      <TextView 
       android:id="@+id/tvXA" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="XA" /> 


     </RadioGroup> 


    </LinearLayout> 

Antwort

1

Sie betrachten können, wie unten, um ein Layout anstelle von Textview Widgets innerhalb Radiogroup mit Ausrichtung horizontal hinzuzufügen.

Schauen Sie sich dieses Beispiel an und sehen Sie, ob es das ist, wonach Sie suchen.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_horizontal" 
android:orientation="vertical" 
android:paddingBottom="10dp" 
android:paddingLeft="10dp" 
android:paddingTop="10dp"> 


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

     <ToggleButton 
      android:id="@+id/toggleOnlineStatus" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/add" 
      android:checked="true" 
      android:layout_margin="12dp" 
      android:textOff="" 
      android:textOn="" /> 

     <ToggleButton 
      android:id="@+id/toggleAwayStatus" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/add" 
      android:layout_margin="12dp" 
      android:textOff="" 
      android:textOn="" /> 

     <ToggleButton 
      android:id="@+id/toggleDNDStatus" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/add" 
      android:layout_margin="12dp" 
      android:textOff="" 
      android:textOn="" /> 

     <ToggleButton 
      android:id="@+id/toggleXAStatus" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/add" 
      android:layout_margin="12dp" 
      android:textOff="" 
      android:textOn="" /> 

    </RadioGroup> 

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

     <TextView 
      android:id="@+id/tvOnline" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Online" /> 

     <TextView 
      android:id="@+id/tvAway" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Away" /> 

     <TextView 
      android:id="@+id/tvDND" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Away" /> 

     <TextView 
      android:id="@+id/tvXA" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Away" /> 

    </LinearLayout> 

Dieses Display ist unten. enter image description here

+0

Ist die zweite 'LinearLayout' innerhalb der ersten? Wenn ja, wird auf der rechten Seite die 'TextView' angezeigt. –

+0

Überprüfen Sie Ihr übergeordnetes lineares Layout, ich änderte die Ausrichtung auf vertikal statt horizontal, dass Sie – Inducesmile

+0

Awesome verwendet. Das funktioniert. Musste eine Füllung machen, um den Text auf die Knöpfe auszurichten. Danke! –

0

können Sie verwenden android:drawableTop Attribut in ToggleButton Element:

 <ToggleButton 
      android:id="@+id/toggleOnlineStatus" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:drawableTop="@drawable/style_toggle_button" 
      android:checked="true" 
      android:textOff="Online" 
      android:textOn="Online" /> 
+0

Das hat auch nicht geklappt. –

Verwandte Themen