Android 相对布局与 ListView

发布于 2024-12-20 03:12:49 字数 2026 浏览 2 评论 0原文

我对其中的每个项目使用带有RelativeLayout 的ListView。我可以正确显示头像、标题和文本信息,但无法让时间戳与标题位于同一行。因此,头像位于左侧,标题位于顶部,时间戳位于同一行的最右侧,文本信息位于正下方。

布局如下:

    <?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="?android:attr/listPreferredItemHeight"
        >

    <ImageView
            android:id="@+id/avatar"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scaleType="center"
            android:layout_marginRight="3dip"
            android:src="@drawable/icon"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            />


    <TextView
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:id="@+id/text_title"
            android:layout_toRightOf="@id/avatar"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:gravity="center_vertical"
            android:textSize="18sp"
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            />

    <TextView    
            android:id="@+id/time_stamp"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_toRightOf="@id/text_title"
            />

    <TextView
            android:id="@+id/text_info"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:layout_toRightOf="@id/avatar"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:singleLine="true"
            />
</RelativeLayout>

I'm using a ListView with a RelativeLayout for each of the Items in it. I can display the avatar, title and text info correctly but I can not get the time_stamp to sit on the same line as the title. So the avatar is on the left, title on top with the timestamp to the far right along the same line and the text_info directly underneath.

Layout is as follows:

    <?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="?android:attr/listPreferredItemHeight"
        >

    <ImageView
            android:id="@+id/avatar"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scaleType="center"
            android:layout_marginRight="3dip"
            android:src="@drawable/icon"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            />


    <TextView
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:id="@+id/text_title"
            android:layout_toRightOf="@id/avatar"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:gravity="center_vertical"
            android:textSize="18sp"
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            />

    <TextView    
            android:id="@+id/time_stamp"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_toRightOf="@id/text_title"
            />

    <TextView
            android:id="@+id/text_info"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:layout_toRightOf="@id/avatar"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:singleLine="true"
            />
</RelativeLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

腻橙味 2024-12-27 03:12:49

对于 time_stamp TextView,使用 layout_alignParentRight="true"layout_alignTop 设置为标题 TextView。因此它将位于列表的右侧,顶部将与标题对齐。

For time_stamp TextView, use layout_alignParentRight="true" and layout_alignTop set to the title TextView. So it will be on the right of the list and top will be aligned with title.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文