Android 相对布局与 ListView
我对其中的每个项目使用带有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于
time_stamp
TextView,使用layout_alignParentRight="true"
和layout_alignTop
设置为标题 TextView。因此它将位于列表的右侧,顶部将与标题对齐。For
time_stamp
TextView, uselayout_alignParentRight="true"
andlayout_alignTop
set to the title TextView. So it will be on the right of the list and top will be aligned with title.