etsy / AndroidStaggeredGrid

An Android staggered grid view which supports multiple columns with rows of varying sizes.
https://github.com/etsy/AndroidStaggeredGrid
4.76k stars 1.13k forks source link

Item no longer visible when scroll single item. #176

Closed HareshChhelana closed 9 years ago

HareshChhelana commented 9 years ago

I have set items based on web service response and set app:column_count="2" in xml.

Now when i get only single item from web response item shown in StaggeredGridfine but if i scroll StaggeredGridthen item goes away and no longer visible in StaggeredGrid.

is any one face same issue ? or any one help me to resolve this issue ?

Thanks a lot in advance.

ketanMuttha commented 9 years ago

I am also facing the same issue apart from that, if the girdview scrolls continuously says 6-7 times. the whole list view is invisible. I am trying to fix this issue but did not get any pointer. Did you get any workaround for this issue?

HareshChhelana commented 9 years ago

I recently found solution for this problem, Just try to check child count > 1 in 'offsetChildrenTopAndBottom' in StaggeredGridView class. Check out my peace of code to resolve my problem -

protected void offsetChildrenTopAndBottom(final int offset, final int column) { if (DBG) Log.d(TAG, "offsetChildrenTopAndBottom: " + offset + " column:" + column); if(getChildCount()>1) {
final int count = getChildCount(); for (int i = 0; i < count; i++) { final View v = getChildAt(i); if (v != null && v.getLayoutParams() != null && v.getLayoutParams() instanceof GridLayoutParams) { GridLayoutParams lp = (GridLayoutParams) v.getLayoutParams(); if (lp.column == column) { v.offsetTopAndBottom(offset); } } } offsetColumnTopAndBottom(offset, column); } }