Android让ListView记住上次滑动到的位置

来源:互联网 发布:初中课本同步软件 编辑:程序博客网 时间:2024/05/19 15:23

近在应用开发中为了做到更好的用户体验,需要让ListView记住上次滑动到的位置,使用getScrollY()方法总是返回0,到最后也没搞懂是为啥。

// save index and top position  int index = mList.getFirstVisiblePosition();  View v = mList.getChildAt(0);  int top = (v == null) ? 0 : v.getTop();  // ...  // restore  mList.setSelectionFromTop(index, top); 
0 0