[英]ListView cut last item
我有一个与此XML的片段:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/footer">
<My.Views.NoResultPanel
style="@style/default_no_result_panel"
android:id="@+id/noResultPanel"
local:textID="@string/no_chat" />
<My.Views.LoadingPanel
style="@style/default_loading_panel"
android:id="@+id/loadingPanel"
local:textID="@string/loading_chat" />
<ListView
android:id="@+id/lvChat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="8dp"
android:stackFromBottom="true"
android:listSelector="@android:color/transparent" />
<View
style="@style/default_divider"
android:layout_gravity="bottom" />
</FrameLayout>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="8dp">
<ImageView
android:id="@+id/imgAttachment"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_attachment_grey600_24dp"
android:layout_alignParentLeft="true" />
<EditText
android:id="@+id/txtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/imgVisibility"
android:layout_toRightOf="@+id/imgAttachment"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:layout_marginLeft="4dp"
android:maxLines="3"
android:inputType="textShortMessage"
android:hint="@string/write_a_message_here" />
<ImageView
android:id="@+id/imgVisibility"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:src="@drawable/ic_eye_grey600_24dp"
android:layout_toLeftOf="@+id/imgSend" />
<ImageView
android:id="@+id/imgSend"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_send_grey600_24dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
</RelativeLayout>
我需要模拟聊天,所以我使用的是android:stackFromBottom
问题是,当我第一次打开该片段时,我发现最后一个项目是“ cutted”。 这是片段的屏幕截图。
我做错了什么?
更新的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="8dp">
<ImageView
android:id="@+id/imgAttachment"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_attachment_grey600_24dp"
android:layout_alignParentLeft="true"
android:background="@drawable/Default_clicked_view_rounded" />
<EditText
android:id="@+id/txtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/imgVisibility"
android:layout_toRightOf="@+id/imgAttachment"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:layout_marginLeft="4dp"
android:maxLines="3"
android:inputType="textShortMessage"
android:hint="@string/write_a_message_here" />
<ImageView
android:id="@+id/imgVisibility"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:src="@drawable/ic_eye_grey600_24dp"
android:layout_toLeftOf="@+id/imgSend"
android:background="@drawable/Default_clicked_view_rounded" />
<ImageView
android:id="@+id/imgSend"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_send_grey600_24dp"
android:layout_alignParentRight="true"
android:background="@drawable/Default_clicked_view_rounded" />
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/footer">
<My.Views.NoResultPanel
style="@style/default_no_result_panel"
android:id="@+id/noResultPanel"
local:textID="@string/no_chat" />
<My.Views.LoadingPanel
style="@style/default_loading_panel"
android:id="@+id/loadingPanel"
local:textID="@string/loading_chat" />
<ListView
android:id="@+id/lvChat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="8dp"
android:stackFromBottom="true"
android:listSelector="@android:color/transparent" />
<View
style="@style/default_divider"
android:layout_gravity="bottom" />
</FrameLayout>
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
您的FrameLayout是匹配的父项,因此它首先覆盖了整个屏幕,因此不确定其下方的新布局@ + id / footer ...在其顶部您会覆盖底部的RelativeLayout(即页脚),因此只需将布局更改为。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
//your Footer Layout will always stay in bottom
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="8dp">
<ImageView
android:id="@+id/imgAttachment"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_attachment_grey600_24dp"
android:layout_alignParentLeft="true" />
<EditText
android:id="@+id/txtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/imgVisibility"
android:layout_toRightOf="@+id/imgAttachment"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:layout_marginLeft="4dp"
android:maxLines="3"
android:inputType="textShortMessage"
android:hint="@string/write_a_message_here" />
<ImageView
android:id="@+id/imgVisibility"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:src="@drawable/ic_eye_grey600_24dp"
android:layout_toLeftOf="@+id/imgSend" />
<ImageView
android:id="@+id/imgSend"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_send_grey600_24dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
//your FrameLayout now will adjust above footer
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/footer"> --------change from +id to id now
<My.Views.NoResultPanel
style="@style/default_no_result_panel"
android:id="@+id/noResultPanel"
local:textID="@string/no_chat" />
<My.Views.LoadingPanel
style="@style/default_loading_panel"
android:id="@+id/loadingPanel"
local:textID="@string/loading_chat" />
<ListView
android:id="@+id/lvChat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="8dp"
android:stackFromBottom="true"
android:listSelector="@android:color/transparent" />
<View
style="@style/default_divider"
android:layout_gravity="bottom" />
</FrameLayout>
</RelativeLayout>
更新:请尝试将android:transcriptMode="alwaysScroll"
属性添加到listView
设置列表的记录方式。 在脚本模式下,列表滚动到底部以使新项目在添加时可见,这样列表将自动滚动到底部。
必须是您引用doc的以下常量值之一。
用垂直方向的LinearLayout替换您的父RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="1"
android:layout_above="@+id/footer">
....
</FrameLayout>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
....
</RelativeLayout>
</LinearLayout>
FrameLayout将与父高度匹配
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.