Android Push Door effect

Source: Internet
Author: User
Tags gety

 Public classMainactivityextendsrelativelayout{PrivateScroller Scroller; Privatecontext Context; Private intwidth; Private intheight; PrivateImageView ImageView; Private intMlastdowny = 0; Private intMcurryy; Private intmdely; Private BooleanMcloseflag =false;  PublicMain_skip (Context context, AttributeSet attrs) {Super(context, attrs);  This. Context =context;    Initview (); }        Private voidInitview () {//This interpolator you can set something else I chose here is a bounce effect interpolatorBounceinterpolator interpolator =NewBounceinterpolator (); Scroller=NewScroller (Context,interpolator); WindowManager Manager=(WindowManager) context. Getsystemservice (Context.window_service); Displaymetrics Metrics=NewDisplaymetrics ();        Manager.getdefaultdisplay (). Getmetrics (metrics); Width=Metrics.widthpixels; Height=Metrics.heightpixels; //Here you have to set a transparent background, otherwise it will affect you to see the underlying layout         This. SetBackgroundColor (Color.argb (0, 0, 0, 0)); ImageView=NewImageView (context); Layoutparams params=Newlayoutparams (layoutparams.match_parent, layoutparams.match_parent);        Imageview.setlayoutparams (params);        Imageview.setscaletype (SCALETYPE.FIT_XY);        Imageview.setimageresource (R.DRAWABLE.A);                    AddView (ImageView); }     Public voidSetbgimg (intResID)    {Imageview.setimageresource (ResID); }         Public voidsetbgimg (drawable drawable) {imageview.setimagedrawable (drawable); }        //push the door to the animation     Public voidSetanimation (intStarty,intDyintduration) {Scroller.startscroll (0, Starty, 0, dy, duration);    Invalidate (); } @Override Public Booleanontouchevent (Motionevent event) {Switch(Event.getaction ()) { CaseMotionEvent.ACTION_DOWN:mLastDownY= (int) event.gety (); System.err.println ("Action_down=" +mlastdowny); return true;  CaseMotionEvent.ACTION_MOVE:mCurryY= (int) event.gety (); System.err.println ("Action_move=" +mcurryy); Mdely= Mcurryy-Mlastdowny; if(Mdely < 0) {ScrollTo (0,-mdely); System.err.println ("-------------  " +mdely); }             Break;  CaseMotionEvent.ACTION_UP:mCurryY= (int) event.gety (); Mdely= Mcurryy-Mlastdowny; if(Mdely < 0){                if(Math.Abs (mdely) &GT;HEIGHT/2) {setanimation ( This. getscrolly (), height, 450); Mcloseflag=true; }Else{setanimation ( This. getscrolly (),- This. getscrolly (), 1000); }            }             Break; default:             Break; }        return Super. Ontouchevent (event); } @Override Public voidComputescroll () {if(Scroller.computescrolloffset ()) {ScrollTo (Scroller.getcurrx (), Scroller.getcurry ()); //don't forget to update the interfacepostinvalidate (); }Else {              if(mcloseflag) { This. setvisibility (View.gone); }         }        Super. Computescroll (); }}

Android Push Door effect

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.