2010-11-20 5 views
1

Ich möchte meine Reihe Elemente wie folgt aussehen: alt textWie kann ich mein ListViewItem wie die Twitter App aussehen lassen?

Ich möchte ein Bild auf der linken Seite haben, oben und unten Text und ein Datum. Ich habe angefangen, sie zu legen, aber ich bin nicht sicher, wie mit dem Rest des XML gehen:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout01" xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:id="@+id/avatarImageView"> 
    </ImageView> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/usernameTextView" 
     android:text="username" 
     android:layout_toRightOf="@+id/avatarImageView" 
     android:layout_alignParentTop="true"> 
    </TextView> 

    <TextView 
     android:id="@+id/bodyTextView" 
     android:layout_below="@+id/usernameTextView" 
     android:layout_toRightOf="@+id/avatarImageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="body"> 
    </TextView> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/usernameTextView" 
     android:id="@+id/dateTextView" 
     android:text="date"> 
    </TextView> 
</RelativeLayout> 

Antwort

3

Sie wollen RelativeLayout überprüfen, ist es viel einfacher für Layouts wie diese, würde es sein, etwas wie.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:padding="6dip"> 

<ImageView id="@+id/badge" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    .../> 

<TextView id="@+id/title" 
    android:layout_toRightOf="@id/badge" 
    android:layout_alignParentTop="true" 
    .... 
    /> 

<TextView id="@+id/body" 
    android:layout_below="@id/title" 
    android:layout_toRightOf="@id/badge" 
    .... 
    /> 
</RelativeLayout> 

Andernfalls müssen Sie gemischte LinearLayouts, z. ein äußeres Links-Rechts-Linearlayout, dann ein verschachteltes vertikales Lineaar-Layout für den Titel & Körper usw.