Created
June 21, 2014 15:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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?