如何将 ListView 滚动到底部? [英] How to scroll ListView to the bottom?
问题描述
我虽然这将是一项简单的任务,但显然没有办法将列表视图滚动到底部.我发现的所有解决方案都使用 setSelection(lastItem)
方法的变体,该方法仅将选择设置为最后一个项目,但不会滚动到它的底部.
I though this would be a simple task, but apparently there is no way to scroll listview to the bottom. All solutions that I found are using variations of setSelection(lastItem)
method which only sets selection to last item, but does not scrolls to the bottom of it.
就我而言,我有一个空的列表视图(带有很长的 empty view 标题集),我想滚动到它的底部.
In my case I have a empty listview (with a long empty view header set) and I want to scroll to bottom of it.
那么,有没有办法做到这一点?
So, is there a way to do it?
所以对于那些有兴趣的人来说,可行的解决方案是:
So for those who are interested the working solution is:
getListView().setSelectionFromTop(0, -mHeader.getHeight());
和
getListView().scrollTo(mOffset)
这也适用,具有右偏移量(根据当前滚动位置计算),但可能会给您带来一些意想不到的结果.
This also works, with right offset (calculated based on current scroll position), but might give you some unexpected results.
推荐答案
尝试使用 list.scrollTo(0, list.getHeight());
这篇关于如何将 ListView 滚动到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!