如何将ListView滚动到底部? [英] How to scroll ListView to the bottom?
问题描述
我虽然这将是一个简单的任务,但是显然没有办法将listview滚动到底部。我发现的所有解决方案都使用 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.
在我的情况下,我有一个空的listview(设置了一个长的 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 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屋!