/// how to scroll to a position in a listView
int index = mList.getFirstVisiblePosition();
View v = mList.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
// ...
// restore
mList.setSelectionFromTop(index, top);
int index = mList.getFirstVisiblePosition();
View v = mList.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
// ...
// restore
mList.setSelectionFromTop(index, top);
本文详细介绍了如何在Android ListView中滚动到指定位置,并通过使用mList.getFirstVisiblePosition()和mList.getChildAt(0)来获取可视区域的第一个视图,进而计算顶部偏移量,实现滚动到特定位置的同时恢复之前的选择项。

被折叠的 条评论
为什么被折叠?



