有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使我的ListViewItem看起来像Twitter应用程序?

我希望我的行项目如下所示: alt text

我想有一个左边的图像,顶部和底部的文本和日期。我已经开始规划,但不确定如何处理XML的其余部分:

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

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

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

共 (1) 个答案

  1. # 1 楼答案

    你会想看看RelativeLayout,像这样的布局容易得多,就像这样

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

    否则,您需要嵌套混合线性布局,例如从左到右的外部线性布局,然后是标题和标题的嵌套垂直线性布局;身体等