android - RecyclerView - animate change of grid layout manager columns -


i want animate change of recyclerviews gridlayoutmanager. defaulty show list of items in grid 3 columns , user can select show more or less columns.

i views in recyclerview move/scale new positions, have no idea how done.

what want in end

  • allow scale grid via expand/contract touch gesture => know how that
  • animate change of layoutmanager

does know how can animate change of layoutmanager?

the source of inspiration here google photos app,the stock sony gallery app

there 2 approaches can go with:

  1. you modify spancount of gridlayoutmanager using setspancount(int)

  2. you set high span count(~100) use spansizelookup change per item spansize on fly.

    • i have used gist provided musenkishi,for this answer provide animator animate changes in grid layout changes
    • i have used approach in sample github project implementing same.
    • caveats:
      • i have used click listener keep modifying the span size up.this changed itemgesturelistener capture pinch zoom events , change accordingly.
      • you need determine way choose span count items in row occupy entire screen width (and hence not see empty space)
      • you call notifyitemrangechanged using runnable post delayed since cannot call notifychanged methods within bindview/createview etc.
      • after changing span size,you need notifyitemrangechanged appropriate range items displayed on screen shifted accordingly.i have used (code @ bottom)

this not complete solution 2 hour solution same.you can improve on points mentioned :). hope keep updating sample since kind of views have fascinated me. not view final solution particular way of achieving approach. if use staggerredlayoutmanager instead,you avoid blank spaces between items.

public int calculaterange() {      int start = ((gridlayoutmanager)        grv.getlayoutmanager()).findfirstvisibleitemposition();      int end = ((gridlayoutmanager) grv.getlayoutmanager()).findlastvisibleitemposition();      if (start < 0)          start = 0;      if (end < 0)          end = getitemcount();      return end - start;   } 

Comments