RecycleView 瀑布流滑动移位

RecycleView StaggeredLayoutManager(瀑布流)滑动的时候,默认会出现item移动的问题,需以下来个步骤来解决:

  附上StaggeredLayoutManager中的一段源码:

    

 /**
* Does not do anything to hide gaps.
*/
public static final int GAP_HANDLING_NONE = 0; @Deprecated
public static final int GAP_HANDLING_LAZY = 1; /**
* When scroll state is changed to {@link RecyclerView#SCROLL_STATE_IDLE}, StaggeredGrid will
* check if there are gaps in the because of full span items. If it finds, it will re-layout
* and move items to correct positions with animations.
* <p>
* For example, if LayoutManager ends up with the following layout due to adapter changes:
* <pre>
* AAA
* _BC
* DDD
* </pre>
* <p>
* It will animate to the following state:
* <pre>
* AAA
* BC_
* DDD
* </pre>
*/
public static final int GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS = 2;

StaggeredLayoutManager

1: 滑动中,不处理 gap:

   mStaggeredLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);

 2: 给每个 item,设置大小:

   viewHolder.cardView.setLayoutParams(layoutParams);

上一篇:Codeforces Gym 100513F F. Ilya Muromets 线段树


下一篇:python学习笔记(十 四)、web.py