from an answer to one of my other questions, I found a Google Demo subclass of ListView that allows you to reorder an item.
The demo works great, but it's hard for me to understand how it works: When an item is dragged above / below the edges of the ListView, the ListView starts scrolling up / down to open new items. The necessary calculation uses different parameters of the ScrollView subroutine:
public boolean handleMobileCellScroll(Rect r) { int offset = computeVerticalScrollOffset(); int height = getHeight(); int extent = computeVerticalScrollExtent(); int range = computeVerticalScrollRange(); int hoverViewTop = r.top; int hoverHeight = r.height(); if (hoverViewTop <= 0 && offset > 0) { smoothScrollBy(-mSmoothScrollAmountAtEdge, 0); return true; } if (hoverViewTop + hoverHeight >= height && (offset + extent) < range) { smoothScrollBy(mSmoothScrollAmountAtEdge, 0); return true; } return false; }
height - the height of the ListView itselfoffset is the scroll position = how many units / pixels have been scrolled up / downrange is the height of the full content.extent - well, what is it?
ListView inherits computeVerticalScrollExtent() from the View , and the document says:
Calculate the vertical offset of the vertical scrollbar width within the horizontal range. This value is used to calculate the position of the thumb within the scroll bar.
If you look at code computeVerticalScrollExtent() , not one of the basements is implemented, but only directly View : It simply returns the height of the view.
This makes sense: if the ListView / ScrollView is 500 in height, the portion of the scroll content that is visible at a time is also 500. Is this a ScrollExtent value? Why is ScrollExtent required? Why not just use getHeight () directly?
I think something is missing and I am glad to any hint!
android android-listview listview android-scrollview
Andrei Herford
source share