Skip to content

资料库列表浏览进度保存和恢复

Logan Guo edited this page Jul 7, 2016 · 4 revisions

浏览资料库列表时切换目录需要保存和恢复上级目录的浏览位置。

  1. 当进入新的目录时,列表置顶显示
  2. 当返回上级目录时,恢复到以前的位置

由于存在多层目录,所以使用类似于返回栈的方式管理每一级目录的进度。

private Map<String, ScrollState> scrollPostions = Maps.newHashMap();

获取当前目录浏览位置的方法是

final String pathJoin = Utils.pathJoin(repoId, currentPath);
final int index = mListView.getFirstVisiblePosition();
final View v = mListView.getChildAt(0);
final int top = (v == null) ? 0 : (v.getTop() - mListView.getPaddingTop());

恢复上级目录浏览位置的方法是

mListView.setSelectionFromTop(state.index, state.top);

ScrollState类

private class ScrollState {
        public int index;
        public int top;

        public ScrollState(int index, int top) {
            this.index = index;
            this.top = top;
        }
    }

相关应用场景

滑动位置置顶

  1. 手动刷新时
  2. 加载网络数据时
  3. 进入子目录时
  4. 从活动页面跳转过来时

恢复原浏览进度

  1. 按下返回键返回上级目录时
  2. home up按钮返回上级目录时
  3. resume当前页面时(默认行为)

Link