2010-12-30 12 views
4

Ich begann mit Fedor's ListView implementation. Hier ist der XML-Code für mein Listview-Element:Android-Layout - stack zwei TextViews vertikal, in einer ListView-Zeile

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 
<ImageView 
     android:id="@+id/image" 
     android:layout_width="50dip" 
     android:layout_height="50dip" android:src="@drawable/stub" android:scaleType="centerCrop"/> 
<TextView 
     android:id="@+id/name" 
     android:layout_width="0px" 
     android:layout_height="0px" 
     android:layout_weight="0" android:textSize="20dip" android:layout_marginLeft="10dip"/> 
<TextView 
     android:id="@+id/address" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" android:textSize="16dip" android:layout_marginLeft="10dip"/> 

</LinearLayout> 

Was ich sehe auf meinem Gerät ist die Image und die beiden Textviews angezeigt nacheinander von links nach rechts.

Was ich will ist das ImageView ganz rechts (das ist schon richtig), der Name TextView rechts von der Bildansicht (das ist richtig) und die Adresse TextView, unter dem Namen TextView. Ich bin nicht in der Lage, herauszufinden, wie man das richtig gestaltet.

Bitte beachten Sie, ich weiß, ich könnte nur eine neue Zeile hinzufügen und den Adresstext danach, aber ich möchte, dass diese beiden Elemente unterschiedliche Schriftgrößen haben, so dass dies keine Option ist. Vielen Dank!

Antwort

6

Sie müssen die Ausrichtung des LinearLayouts festlegen und um das zu erreichen, was Sie tun möchten, müssen Sie mehrere davon verwenden. In Pseudo-Code, werden Sie zu tun haben:

<LinearLayout 
    android:orientation="horizontal" 
    ...> 
    <ImageView 
     android:id="@+id/image" 
     ... /> 
    <LinearLayout 
     android:orientation="vertical" 
     ...> 
     <TextView 
      android:id="@+id/name" 
      ...> 

     <TextView 
      android:id="@+id/address" 
      ...> 
    </LinearLayout> 
</LinearLayout> 
+1

Zum Beispiel ist dies ziemlich viel, was Sie für Fragen: https://github.com/commonsguy/cw-andtutorials/blob/master/ 05-FancyList/LunchList/res/layout/row.xml – CommonsWare

+0

perfekt, das ist genau das, was ich vermisst habe. Danke. –

+0

Sollte hier eine Million Punkte bekommen !!! –

Verwandte Themen