开发者

How can I make my ListViewItem look like the Twitter app?

I want my row items to look like this:

How can I make my ListViewItem look like the Twitter app?

I want to have an image on the left, top and bottom text and a date. I have started to lay it out, but am not sure how to proceed with the rest of the XML:

 <?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>


You'll want to check out RelativeLayout, its much easier for layouts like this, it'd be something like.

<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>

Otherwise you need to nest mixed LinearLayouts, e.g. an outer left to right LinearLayout, then a nested vertical Lineaar Layout for title & body, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜