Set Max and Min zoom on TouchEvent in Android -


i copied kind of code make imageview scrollable.

example.setontouchlistener(new view.ontouchlistener() {         @override         public boolean ontouch(view v, motionevent event) {             imageview view = (imageview) v;             view.setscaletype(imageview.scaletype.matrix);             float scale;              dumpevent(event);             //handle touch events here...              switch (event.getaction() & motionevent.action_mask) {                 case motionevent.action_down: //first finger down                     savedmatrix.set(matrix);                     start.set(event.getx(), event.gety());                     log.d(tag, "mode=drag");                     mode = drag;                     break;                 case motionevent.action_up://first finger lifted                  case motionevent.action_pointer_up: //second finger lifted                     mode = none;                     log.d(tag, "mode=none");                     break;                 case motionevent.action_pointer_down: //first , second finger down                     olddist = spacing(event);                     log.d(tag, "olddist=" + olddist);                     if (olddist > 10f) {                         savedmatrix.set(matrix);                         midpoint(mid, event);                         mode = zoom;                         log.d(tag, "mode=zoom");                     }                     break;                 case motionevent.action_move:                     if (mode == drag) {                         matrix.set(savedmatrix);                         matrix.posttranslate(event.getx() - start.x, event.gety() - start.y); //create transformation in matrix of points                     } else if (mode == zoom) {                         //pinch zooming                         float newdist = spacing(event);                         log.d(tag, "newdist=" + newdist);                         if (newdist > 10f) {                             matrix.set(savedmatrix);                             scale = newdist / olddist; //setting scaling of matrix...                             //if scale > 1 means zoom in                             // if scale < 1 means zoom out                             matrix.postscale(scale, scale, mid.x, mid.y);                         }                     }                     break;             }             view.setimagematrix(matrix); //display transformation on screen              return true; //indicate event handled         }  private float spacing(motionevent event) {             float x = event.getx(0) - event.getx(1);             float y = event.gety(0) - event.gety(1);             return floatmath.sqrt(x * x + y * y);         }          /*          * --------------------------------------------------------------------------          * method: midpoint parameters: pointf object, motionevent returns: void          * description: calculates midpoint between 2 fingers          * ------------------------------------------------------------          */          private void midpoint(pointf point, motionevent event) {             float x = event.getx(0) + event.getx(1);             float y = event.gety(0) + event.gety(1);             point.set(x / 2, y / 2);         } 

where have put variable set max , min zoom.

at moment can zoom in or out endless.

kind regards!

you have create min_zoom, max_zoom, , scale follows :

private static final float min_zoom = 1.0f;  private static final float max_zoom = what_you_want;  float scale = math.max(min_zoom, math.min(scale, max_zoom)); 

for more information check answer


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -