2010-12-06 6 views
0

Ich bin relativ neu in Android und frage mich, ob es eine bessere Möglichkeit gibt, dieses Layout zu tun. Ich brauche 4 Etiketten, die auf der linken Seite vertikal gestapelt sind, mit 2 größeren Schriften auf der rechten Seite. Wenn Sie das im Emulator ausführen, ist es genau so, wie ich es brauche, aber gibt es einen bevorzugten Weg?Android - Gibt es eine bessere Möglichkeit, dieses Layout zu erstellen?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/Label1" 
     android:text="Label 1: " 
     android:layout_width="200dp" 
     android:layout_height="wrap_content"/> 
    <TextView 
     android:id="@+id/Label2" 
     android:text="Label 2: " 
     android:layout_below="@id/Label1" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content"/> 
    <TextView 
     android:id="@+id/Label3" 
     android:text="Label 3: " 
     android:layout_below="@id/Label2" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content"/> 
    <TextView 
     android:id="@+id/Label4" 
     android:text="Label 4: " 
     android:layout_below="@id/Label3" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content"/> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_toRightOf="@id/Label1"> 
     <TextView 
      android:id="@+id/Label6" 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:text="Points" 
      android:textStyle="bold" 
      android:textSize="25sp" 
      android:gravity="center_horizontal"/> 
     <TextView 
      android:id="@+id/LabelPoints" 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:text="8.6" 
      android:textStyle="bold" 
      android:textSize="25sp" 
      android:gravity="center_horizontal"/> 
    </LinearLayout> 
</RelativeLayout> 

Antwort

0

Mit dem Aussehen der Dinge können Sie ein wenig unzusammenhängend kommen, wenn Sie beginnen, auf verschiedenen Geräten mit unterschiedlichen Bildschirmgrößen/Dichten zu implementieren.

Wenn dies mein Problem wäre, wäre ich versucht, ein zusätzliches LinearLayout zu verwenden und diese mit einer Gewichtung auszurichten. Siehe unten ..

Hope this Sie hilft, wenn es nicht zu spät ist :)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal"> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_weight="1"> 
     <TextView 
      android:id="@+id/Label1" 
      android:text="Label 1: " 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:id="@+id/Label2" 
      android:text="Label 2: " 
     android:layout_below="@id/Label1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:id="@+id/Label3" 
      android:text="Label 3: " 
      android:layout_below="@id/Label2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:id="@+id/Label4" 
      android:text="Label 4: " 
      android:layout_below="@id/Label3" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:layout_toRightOf="@id/Label1"> 
     <TextView 
      android:id="@+id/Label6" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Points" 
      android:textStyle="bold" 
      android:textSize="25sp" 
      android:gravity="center_horizontal"/> 
     <TextView 
      android:id="@+id/LabelPoints" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="8.6" 
      android:textStyle="bold" 
      android:textSize="25sp" 
      android:gravity="center_horizontal"/> 
    </LinearLayout></LinearLayout> 
0

Mark, ich denke, es ist kein guter Weg ist, weil Android docs bezieht sich, dass relativ effizienter ist. Sie können es hier finden: http://developer.android.com/guide/topics/ui/layout/relative.html

„A RelativeLayout ein sehr leistungsfähiges Programm, ist ein Benutzer Schnittstelle für die Gestaltung, weil es verschachtelte Ansicht Gruppen beseitigen und halten Sie Ihre Layout Hierarchie flach, was die Leistung verbessert.“

+0

Es wird für kleine Fälle in Ordnung sein - es ist nicht so, als ob er aus LinearLayouts eine Tabellenstruktur zeichnet – ataulm

0

kann es auch mit TableLayout tun. Sie können also Ihre Beschriftungen in einer Reihe hinzufügen (TableRow). hoffentlich ist es nützlich für Sie :-)