RecycleView 瀑布流滑動移位


 

RecycleView StaggeredLayoutManager(瀑布流)滑動的時候,默認會出現item移動的問題,需以下來個步驟來解決:

  附上StaggeredLayoutManager中的一段源碼:

    

 1 /**
 2      * Does not do anything to hide gaps.
 3      */
 4     public static final int GAP_HANDLING_NONE = 0;
 5 
 6     @Deprecated
 7     public static final int GAP_HANDLING_LAZY = 1;
 8 
 9     /**
10      * When scroll state is changed to {@link RecyclerView#SCROLL_STATE_IDLE}, StaggeredGrid will
11      * check if there are gaps in the because of full span items. If it finds, it will re-layout
12      * and move items to correct positions with animations.
13      * <p>
14      * For example, if LayoutManager ends up with the following layout due to adapter changes:
15      * <pre>
16      * AAA
17      * _BC
18      * DDD
19      * </pre>
20      * <p>
21      * It will animate to the following state:
22      * <pre>
23      * AAA
24      * BC_
25      * DDD
26      * </pre>
27      */
28     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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM