Andrei Herford Andrei Herford - 1 year ago 171
Android Question

What is the VerticalScrollExtent in Android ScrollView?

from an answer to one of my other questions I found an Google Demo of a ListView subclass that allows item reorder.

The demo works great, but I am having some trouble to understand how the it works:
When an item is dragged above/below the bounds of the ListView, the ListView starts scrolling up/down to reveal new items. The necessary calculation uses different parameters of the underling ScrollView:

public boolean handleMobileCellScroll(Rect r) {
int offset = computeVerticalScrollOffset();
int height = getHeight();
int extent = computeVerticalScrollExtent();
int range = computeVerticalScrollRange();
int hoverViewTop =;
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
    is the height of the ListView itself

  • offset
    is the scroll position = how many units/pixels have been scrolled up/down

  • range
    is the height of the complete content.

  • extent
    - well, what is this?

and the docu says:

Compute the vertical offset of the vertical scrollbar's thumb within
the horizontal range. This value is used to compute the position of
the thumb within the scrollbar's track.

If one looks at the code
is not implemented by one of the sublasses but only directly by
: It simply returns the height of the view.

This makes sense: If the ListView/ScrollView has a height of 500, the part of the scroll content that is visible at a time is also 500. Is this the meaning of the ScrollExtent? Why is ScrollExtent necessary? Why not simply use getHeight() directly?

I think I am missing something and I am happy about any hint!

Answer Source

It's kinda late, but hope it's ok.

1) The method actually is implemented by the subclasses. For example, this is what it looks like for AbsListView (ListView's superclass).
2) View's height can be different from its vertical scroll's height - just imagine a View with weird top/bottom padding .

These two points pretty much make other questions irrelevant :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download