Ari*_*Ari 7 android android-adapter android-recyclerview
我有一个由LinearlayoutManager管理的RecyclerView,如果我将项目1与0交换然后调用mAdapter.notifyItemMoved(0,1),则移动动画会导致屏幕滚动.我该怎样预防呢?
可悲的是,yigit提出的解决方法滚动RecyclerView到顶部.这是我发现的最好的解决方法:
// figure out the position of the first visible item
int firstPos = manager.findFirstCompletelyVisibleItemPosition();
int offsetTop = 0;
if(firstPos >= 0) {
View firstView = manager.findViewByPosition(firstPos);
offsetTop = manager.getDecoratedTop(firstView) - manager.getTopDecorationHeight(firstView);
}
// apply changes
adapter.notify...
// reapply the saved position
if(firstPos >= 0) {
manager.scrollToPositionWithOffset(firstPos, offsetTop);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3228 次 |
| 最近记录: |