Scalegesturedetector scaling View

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.