android - StaggeredGridLayoutManager returns wrong verticalScrollOffset -


i'm doing same here (https://github.com/kmshack/android-parallaxheaderviewpager), recyclerview in tabs.

recyclerview in 1 tab has items big height , first 1 not visible under header. @ point call recyclerview's computeverticalscrolloffset() (that calls staggeredgridlayoutmanager's method) , returns wrong values. if change header height make first item visible i'm getting right values.

is there known solution/fix this?

p.s. use linearlayoutmanager , right values if first item not visible under header

i believe error findfirstvisibleposition() , findlastvisibleposition() used in computescrolloffset() function arguments. if use equal row height computeverticalscrolloffset() returns weird numbers. if replace them recyclerview.getchildat(0) , recyclerview.getchildat(recyclerview.getchildcount() - 1) works.

so can write our own function:

view firstitemview = recyclerview.getchildat(0); view lastitemview = recyclerview.getchildat(recyclerview.getchildcount() - 1);  int firstitem = recyclerview.getchildlayoutposition(firstitemview); int lastitem = recyclerview.getchildlayoutposition(lastitemview); int itemsbefore = firstitem;  int laidoutarea = recyclerview.getlayoutmanager().getdecoratedbottom(lastitemview) - recyclerview.getlayoutmanager().getdecoratedtop(firstitemview); int itemrange = lastitem - firstitem + 1; float avgsizeperrow = (float) laidoutarea / itemrange;  int offset = (int) (itemsbefore * avgsizeperrow + recyclerview.getlayoutmanager().getpaddingtop() - recyclerview.getlayoutmanager().getdecoratedtop(firstitemview)); 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -