在Listview中使用一些高级标签来满足一些特殊的需求。
android:transcriptMode
Sets the transcript mode for the list. In transcript mode, the list scrolls to the bottom to make new items visible when they are added.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
disabled | 0 | Disables transcript mode. This is the default value. |
normal | 1 | The list will automatically scroll to the bottom when a data set change notification is received and only if the last item is already visible on screen. |
alwaysScroll | 2 | The list will automatically scroll to the bottom, no matter what items are currently visible. |
这个是官方API文档的描述,android:transcriptMode本人的理解就是用来设置Listview自动滚动到底部的类型。
- disabled就是默认,不会自动滚动到底部
- normal 当键盘弹出时会自动滚动到底部,调用notifyDataSetChanged是不会自动滚动的。(这个适合聊天页面使用)
- alwaysScroll默认滚动到底部,键盘弹出和调用notifyDataSetChanged都会自动滚动到底部
android:stackFromBottom
Used by ListView and GridView to stack their content from the bottom.
Must be a boolean value, either “true” or “false”.
This may also be a reference to a resource (in the form “@[package:]type:name”) or theme attribute (in the form “?[package:][type:]name”) containing a value of this type.
This corresponds to the global attribute resource symbol stackFromBottom.
这个参数有两个选择,
-“false”:默认选择,Listview将从顶部开始填充
-“true”:从底部开始填充