Android custom imageview with zoom and scroll
<p>I am trying to create an image view with zoom and Scroll. Checked many solutions over internet and i didn't get an accurate result. My current imageview is having the scroll property.Need to add a zoom. </p>

<pre><code>public class MapView extends ImageView {

    private GestureDetectorCompat gestureDetector;
    private OverScroller overScroller;

    private final int screenW;
    private final int screenH;

    private int positionX = 0;
    private int positionY = 0;

    public MapView(Context context) {
        super(context);
        // We need screen dimensions to make sure we don't over scroll the image
        DisplayMetrics dm = getResources().getDisplayMetrics();
        screenW = dm.widthPixels;
        screenH = dm.heightPixels;

        gestureDetector = new GestureDetectorCompat(context, gestureListener);
        overScroller = new OverScroller(context);
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        return true;
    }

    @Override
    public void computeScroll() {
        super.computeScroll();
        // computeScrollOffset() returns true only when the scrolling isn't
        // already finished
        if (overScroller.computeScrollOffset()) {
            positionX = overScroller.getCurrX();
            positionY = overScroller.getCurrY();
            scrollTo(positionX, positionY);
        } else {
            // when scrolling is over, we will want to "spring back" if the
            // image is overscrolled
            overScroller.springBack(positionX, positionY, 0, getMaxHorizontal(), 0, getMaxVertical());
        }
    }

    private int getMaxHorizontal() {
        return (Math.abs(getDrawable().getBounds().width() - screenW));
    }



    private int getMaxVertical() {
        return (Math.abs(getDrawable().getBounds().height() - screenH));
    }



    private SimpleOnGestureListener gestureListener = new SimpleOnGestureListener() {

        @Override
        public boolean onDown(MotionEvent e) {
            overScroller.forceFinished(true);
            ViewCompat.postInvalidateOnAnimation(MapView.this);
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                               float velocityY) {
            overScroller.forceFinished(true);
            overScroller.fling(positionX, positionY, (int) -velocityX, (int) -velocityY, 0, getMaxHorizontal(), 0,
                    getMaxVertical());
            ViewCompat.postInvalidateOnAnimation(MapView.this);
            return true;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2,
                                float distanceX, float distanceY) {
            overScroller.forceFinished(true);
            // normalize scrolling distances to not overscroll the image
            int dx = (int) distanceX;
            int dy = (int) distanceY;
            int newPositionX = positionX + dx;
            int newPositionY = positionY + dy;
            if (newPositionX &lt; 0) {
                dx -= newPositionX;
            } else if (newPositionX &gt; getMaxHorizontal()) {
                dx -= (newPositionX - getMaxHorizontal());
            }
            if (newPositionY &lt; 0) {
                dy -= newPositionY;
            } else if (newPositionY &gt; getMaxVertical()) {
                dy -= (newPositionY - getMaxVertical());
            }
            overScroller.startScroll(positionX, positionY, dx, dy, 0);
            ViewCompat.postInvalidateOnAnimation(MapView.this);
            return true;
        }
    };

}
</code></pre>

<p>Can i get any pointers on this?</p>