Search code examples
androidpicassostaggered-gridview

Android - StaggeredGrid wrong items disposition


I have a problem with my Recycler view and StaggeredGrid which cut the width by 2. I load images into items with Picasso and when I load image first time, they are disposed strangely in the recycler view. After reloading, everything seems good.

I think problem come from image loading : the StaggeredGrid doesn't know the image height the first time, but know after reloading because of cache.

How can i solve this problem ?

enter image description here


Solution

  • Solved by changing gap strategy to :

    StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        manager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
        recyclerView.setLayoutManager(manager);
    

    Change the position of items automatically