Android custom imageview with zoom and scroll -


i trying create image view zoom , scroll. checked many solutions on internet , didn't accurate result. current imageview having scroll property.need add zoom.

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);         // need screen dimensions make sure don't on scroll 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 when scrolling isn't         // finished         if (overscroller.computescrolloffset()) {             positionx = overscroller.getcurrx();             positiony = overscroller.getcurry();             scrollto(positionx, positiony);         } else {             // when scrolling over, want "spring back" if             // image 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 not overscroll image             int dx = (int) distancex;             int dy = (int) distancey;             int newpositionx = positionx + dx;             int newpositiony = positiony + dy;             if (newpositionx < 0) {                 dx -= newpositionx;             } else if (newpositionx > getmaxhorizontal()) {                 dx -= (newpositionx - getmaxhorizontal());             }             if (newpositiony < 0) {                 dy -= newpositiony;             } else if (newpositiony > getmaxvertical()) {                 dy -= (newpositiony - getmaxvertical());             }             overscroller.startscroll(positionx, positiony, dx, dy, 0);             viewcompat.postinvalidateonanimation(mapview.this);             return true;         }     };  } 

can pointers on this?

you might wish check out open source lib: https://github.com/ozeetee/androidimagezoomcrop

it need , way more quite easy trim down need


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo