title: How do I resize my imageview within my scrollview as it is done in this image?
body: <p>I have created a scrollview and an imageview is placed within it. I'd like on scroll for it to resize in the same fashion it is done in the image below but so far I've had little success.</p>
  
  <p>In my attempts the image is resized on scroll but, there is space left over after the resize. How would you modify the below:</p>
  
  <p>Image:</p>
  
  <p><img src="https://i.stack.imgur.com/NYV2t.gif" alt="enter image description here"></p>
  
  <p>My Code so far:</p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;ImageView
              android:layout_gravity="center"
              android:adjustViewBounds="true"
              android:layout_width="601dp"
              android:layout_height="250dp"
              android:paddingTop="0dp"
              android:paddingLeft="0dp"
              android:paddingRight="0dp"
              android:scaleType="fitXY"
              android:id="@+id/contactPic"
              android:src="@drawable/stock"
              android:clickable="true"/&gt;
  </code></pre>
  
  <p><strong>MainActivity:</strong></p>
  
  <pre><code>@Override
  public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
      final ImageView contactPicture = (ImageView) findViewById(R.id.contactPic);
      final RelativeLayout contactLayout = (RelativeLayout) findViewById(R.id.ContactRLayout);
      if (scrollView == contactScrollView) {
          View view = (View) scrollView.getChildAt(scrollView.getChildCount() - 1);
          int distanceFromPageEnd = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
  
          Log.e("onScrollChanged", "distance from bottom = " + String.valueOf(distanceFromPageEnd));
          if (distanceFromPageEnd &gt;= 1408)
          {
         contactPicture.getLayoutParams().height = (distanceFromPageEnd - 1408);
          contactPicture.requestLayout();
          }
      }
  </code></pre>
  
  <p><strong>ScrollViewListener:</strong></p>
  
  <pre><code>    public interface ScrollViewListener {
  
          void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy);
  
      }
  </code></pre>
  
  <p><strong>ObservableScrollView:</strong></p>
  
  <pre><code>public class ObservableScrollView extends ScrollView {
  
      private ScrollViewListener scrollViewListener = null;
  
      public ObservableScrollView(Context context) {
          super(context);
      }
  
      public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
      }
  
      public ObservableScrollView(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public void setScrollViewListener(ScrollViewListener scrollViewListener) {
          this.scrollViewListener = scrollViewListener;
      }
  
      public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
          super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
      }
  
      @Override
      protected void onScrollChanged(int x, int y, int oldx, int oldy) {
          super.onScrollChanged(x, y, oldx, oldy);
          if(scrollViewListener != null) {
              scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
          }
      }
  
  }
  </code></pre>