Skip to content

Instantly share code, notes, and snippets.

@sharoni474
Created June 21, 2014 15:16
Show Gist options
  • Save sharoni474/52526d45a76e872cee91 to your computer and use it in GitHub Desktop.
Save sharoni474/52526d45a76e872cee91 to your computer and use it in GitHub Desktop.
A fix for Daniel Olshansky's DevByte example "ListView Expanding Cells Animation"- collapsing part, when last item is visible from top
int offset = computeVerticalScrollOffset();
int range = computeVerticalScrollRange();
int extent = computeVerticalScrollExtent();
int leftoverExtent = range - offset - extent;
// In Case Items does not fill the screen (More accurate, if last
// Item is reachable from offset 0
boolean isfillingScreen = getBottom() - height +yDelta< getHeight();
// added line
if (!isfillingScreen && leftoverExtent < 0)
leftoverExtent *= -1;
boolean isCollapsingBelowBottom = (yTranslateBottom > leftoverExtent);
boolean isCellCompletelyDisappearing = bottom - yTranslateBottom < 0;
boolean isExtentBeyondRange = leftoverExtent < 0; // fix
// added line
if (!isfillingScreen)
isCollapsingBelowBottom = (yTranslateTop + yTranslateBottom > range) ? false
: isCollapsingBelowBottom;
if (isCollapsingBelowBottom && !isExtentBeyondRange) {
yTranslateTop = yTranslateBottom - leftoverExtent;
// added line - problematic- last item jumps
if (!isfillingScreen)
yTranslateTop = yTranslateTop < range ? 0 : yTranslateTop;
yTranslateBottom = yDelta - yTranslateTop;
} else if (isCellCompletelyDisappearing && !isExtentBeyondRange) {
yTranslateBottom = bottom;
yTranslateTop = yDelta - yTranslateBottom;
}
//added line- jumping when last item is seen from offset 0
if(offset==0 && !isfillingScreen) {
yTranslateBottom+=yTranslateTop;
yTranslateTop = 0;
}
@jordi-chacon
Copy link

@sharoni474, thanks a lot for this fix! I just downloaded the zip and applied your fix. With 30 cells everything works well, but if you change that to just 10 cells, you will see weird things happening when collapsing the top 5-6 elements. Do you have any tips on how to fix that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment