Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果仅仅有footview,在界面第一次添加数据时,会自动滚动到底部!! #24

Open
kaleai opened this issue Apr 16, 2016 · 2 comments
Assignees
Labels

Comments

@kaleai
Copy link
Owner

kaleai commented Apr 16, 2016

复现路径:
初始化不设置数据,仅仅设置底部

异步加载网络,调用list的addAll方法添加数据

使用的是 ObservableArrayList

@kaleai
Copy link
Owner Author

kaleai commented Oct 2, 2016

dataBinding提供的ObservableArrayList的addAll方法最终会触发,adapter的

public void onItemRangeInserted(ObservableList<T> sender, int positionStart, int itemCount) {
           notifyItemRangeInserted(positionStart, itemCount);
           notifyItemRangeChanged(positionStart, itemCount);
}

属于在尾部插入了一堆数据,故我模拟了最正常的方式:

recyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                data.addAll(DataManager.loadData(getBaseContext(), 25));
                adapter.notifyItemRangeInserted(0, 25);

            }
        }, 1000);

发现结果还是会定位到底部的item,说明插入后recyclerView的机制就是会定位到插入的item处。

这个问题和有没有footer无关,可以自行测试。

如果有了header,这个问题确实就可以解决了具体原因未知,可能是header的出现,阻碍了其滚动到新插入item位置的动作。

如果要正常解决这个问题,可以采用下列的list,调用其reset方法即可。
https://github.com/tianzhijiexian/DBinding/blob/master/dbindinglib/src/main/java/kale/dbinding/util/ObservableArrayList.java

@kaleai kaleai added the bug label Dec 8, 2016
@kaleai kaleai self-assigned this Dec 8, 2016
@humanheima
Copy link

应该跟这行代码有关系 adapter.notifyItemRangeInserted(0, 25); ,换成 adapter.notifyDataSetChanged 试一试?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants