title: What is the VerticalScrollExtent in Android ScrollView?
body: <p>from an answer to one of my other questions I found an <a href="http://developer.android.com/shareables/devbytes/ListViewDraggingAnimation.zip">Google Demo of a ListView subclass</a> that allows item reorder. </p>
  
  <p>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:</p>
  
  <pre><code>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 &lt;= 0 &amp;&amp; offset &gt; 0) {
          smoothScrollBy(-mSmoothScrollAmountAtEdge, 0);
          return true;
      }
  
      if (hoverViewTop + hoverHeight &gt;= height &amp;&amp; (offset + extent) &lt; range) {
          smoothScrollBy(mSmoothScrollAmountAtEdge, 0);
          return true;
      }
  
      return false;
  }
  </code></pre>
  
  <ul>
  <li><code>height</code>is the height of the ListView itself</li>
  <li><code>offset</code>is the scroll position = how many units/pixels have been scrolled up/down</li>
  <li><code>range</code>is the height of the complete content. </li>
  <li><strong><code>extent</code> - well, what is this?</strong></li>
  </ul>
  
  <p><code>ListView</code> inherits <code>computeVerticalScrollExtent()</code> from <code>View</code> and the docu says:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>If one looks at the <a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/view/View.java">code</a> <code>computeVerticalScrollExtent()</code> is not implemented by one of the sublasses but only directly by <code>View</code>: <strong>It simply returns the height of the view.</strong></p>
  
  <p>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? <strong>Why is ScrollExtent necessary? Why not simply use getHeight() directly?</strong></p>
  
  <p>I think I am missing something and I am happy about any hint!</p>