Moh*_*bdu 17 android android-appcompat android-recyclerview
打电话时notifyDataSetChanged在RecyclerView 其滚动位置和卷轴不保留顶部,有没有解决方案,保留它的滚动位置?
ser*_*yuz 14
如果您的RecyclerView列表项父项具有"wrap_content"属性,则Recyclerview会再次计算高度并向上滚动.
有两种解决方案:
layout_height="100dp"像这样使用StaggeredGridLayoutManager:
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL));
第二种解决方案更有效率,我建议这一点
不确定这是否解决了您的问题,但我遇到了同样的问题,这是因为我在通知后调用了setAdapter.因此,在通知解决问题后不调用setAdapter.
mAdapter.notifyItemRangeInserted(mAdapter.getItemCount(), list.size() - 1);
recyclerView.setAdapter(); // remove this line.
//Do this only when you're setting the data for the first time or when adapter is null.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17478 次 |
| 最近记录: |