StaggeredGridLayoutManager 瀑布流返回顶部时出现跳跃
来源:互联网 发布:除法公式有几种算法 编辑:程序博客网 时间:2024/06/11 12:58
使用RecyclerView搭配StaggeredGridLayoutManager实现瀑布流时,一般会在Adapter的onBindViewHolder()方法里加载图片,图片高度自适应,使得item的排布错落有致。但是当我们下拉到底部之后,上拉的时候,每一个item又会执行一遍onBindViewHolder()方法,会导致我们滑回到顶部的时候,瀑布流的几个流可能不是平齐的,StaggeredGridLayoutManager会调整排布顺序,使得几个流的顶部平齐,产生了跳跃的现象。
解决办法,给StaggeredGridLayoutManager 的setGapStrategy方法设成GAP_HANDLING_NONE,这样setAutoMeasureEnabled方法就会被置位false。
/** * Sets the gap handling strategy for StaggeredGridLayoutManager. If the gapStrategy parameter * is different than the current strategy, calling this method will trigger a layout request. * * @param gapStrategy The new gap handling strategy. Should be * {@link #GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS} or {@link * #GAP_HANDLING_NONE}. * @see #getGapStrategy() */ public void setGapStrategy(int gapStrategy) { assertNotInLayoutOrScroll(null); if (gapStrategy == mGapStrategy) { return; } if (gapStrategy != GAP_HANDLING_NONE && gapStrategy != GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS) { throw new IllegalArgumentException("invalid gap strategy. Must be GAP_HANDLING_NONE " + "or GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS"); } mGapStrategy = gapStrategy; setAutoMeasureEnabled(mGapStrategy != GAP_HANDLING_NONE); requestLayout(); }
所以我们只需要写一下代码即可:
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
lv_collect.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager)recyclerView.getLayoutManager(); layoutManager.invalidateSpanAssignments(); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); } });
阅读全文
0 0
- StaggeredGridLayoutManager 瀑布流返回顶部时出现跳跃
- StaggeredGridLayoutManager 瀑布流返回顶部时跳跃问题 解决办法
- StaggeredGridLayoutManager瀑布流错乱和顶部空白问题解决
- 瀑布流 RecycleView 的 StaggeredGridLayoutManager?
- 使用StaggeredGridLayoutManager实现瀑布流效果
- 使用StaggeredGridLayoutManager实现瀑布流效果
- 使用StaggeredGridLayoutManager瀑布流,Glide显示图片
- RecyclerView采用StaggeredGridLayoutManager布局的瀑布流效果
- Android RecyclerView+StaggeredGridLayoutManager实现瀑布流图片闪烁问题
- 瀑布流学习、 点击状态栏返回顶部、 点击按钮返回顶部、Label透明度字体跟着变浅的解决方法
- RecyclerView 瀑布流的配置以及它的 StaggeredGridLayoutManager 布局管理器的使用
- RecycleView瀑布流header向上滑动时tab固定在顶部实现方法
- 返回顶部
- 返回顶部
- 返回顶部
- 返回顶部
- 返回顶部
- 返回顶部
- mysql,sql语句大全
- qq第3方登录的JS实现方式 js_sdk
- golang服务健壮性---(异常处理)
- 木马病毒隐身穿墙术解密之文件注入和反弹连接
- struts2配置文件result的name属性有哪些?
- StaggeredGridLayoutManager 瀑布流返回顶部时出现跳跃
- Faster-RCNN_TF代码解读4:config.py
- 初学nodejs -- NodeJs引用外部函数的方法
- Unity3D 设计模式---命令者模式
- django -- cbv,fbv,中间件
- android之HttpURLConnection
- 面试题04:Mind the Gap
- 总结
- C++ 编程小问题