Public class scalegesture implements onscalegesturelistener {
Private float beforefactor;
Private float mpivotx;
Private float mpivoty;
Private view mvsouce;
Private Boolean isfillafter;
Public void setsourceview (view destinyview ){
Mvsouce = destinyview;
}
@ Override
Public Boolean onscale (scalegesturedetector detector ){
If (checkisnull ()){
Return false;
}
Final float factor = detector. getscalefactor ();
Animation animation = new scaleanimation (beforefactor, factor,
Beforefactor, factor, mpivotx, mpivoty );
Animation. setfillafter (true );
Mvsouce. startanimation (animation );
Beforefactor = factor;
Return false;
}
@ Override
Public Boolean onscalebegin (scalegesturedetector detector ){
If (checkisnull ()){
Return false;
}
Beforefactor = 1f;
Mpivotx = detector. getfocusx ()-mvsouce. getleft ();
Mpivoty = mvsouce. gettop () + (mvsouce. getheight ()> 1 );
Return true;
}
@ Override
Public void onscaleend (scalegesturedetector detector ){
If (checkisnull ()){
Return;
}
Final float factor = detector. getscalefactor ();
Final int nwidth = (INT) (mvsouce. getwidth () * factor );
Final int nheight = (INT) mvsouce. getheight ();
Final int nleft = (INT) (mvsouce. getleft ()-(nwidth-mvsouce
. Getwidth () * (mpivotx/mvsouce. getwidth ())));
Final int ntop = (INT) mvsouce. gettop ();
If (isfillafter ){
Mvsouce. layout (nleft, ntop, nleft + nwidth, ntop + nheight );
}
// Must be clear animation. Otherwise will be flicker
// If can not clear animation the layout will keep the size
// Mvsouce. clearanimation ();
}
Public Boolean checkisnull (){
Return mvsouce = NULL? True: false;
}
/**
* If parameter is true that keeping same scale when next scaling.
*
* @ Param isfill
*/
Public void setfillafter (Boolean isfill ){
Isfillafter = isfill;
}
}
/* Define variables in the activity */
Scalegesture SG = new scalegesture ();
Scalegesturedetector detector;
/* In the oncreat Method */
Detector = new scalegesturedetector (view. getcontext (), SG) to be scaled );
SG. setsourceview (view to be scaled );
/* Zooming can be implemented, but the mobile view is not implemented well. You can use scrollby to move the view */
Scalegesturedetector scaling View