Android Picture Drag

Source: Internet
Author: User

The code is as follows:

1 PrivateImageView Mshowimage =(ImageView) Findviewbyid (r.id.mshowimage);2 3Mshowimage.setontouchlistener (NewView.ontouchlistener () {4             intStartX = 0,starty = 0;//x, y coordinates relative to ImageView when touching the screen5             intMX = 0, my=0;//ImageView for the left and right margins of the screen6 @Override7              Public BooleanOnTouch (View V, motionevent e) {8                 Switch(E.getaction ())9                 {Ten                      CaseMotionevent.action_down: OneStartX = (int) E.getx (); AStarty = (int) e.gety (); -                          Break; -                      CaseMotionevent.action_move: theMX = (int) (E.GETRAWX ()-StartX);//current Touch The x-coordinate about the screen minus the x-coordinate about ImageView is the left margin of the ImageView. -MY = (int) (E.getrawy ()-starty-getstatusbarheight ());//same as the left margin principle, but need to subtract the height of the notification bar, if full screen, you do not need to subtract the height of the notification bar -V.layout (Mx,my,mx+v.getwidth (), my+v.getheight ()); -                          Break; +                 } -                 return true; +             } A         }); at  -  -Get Notification Bar height - Private intgetstatusbarheight () { -Rect rect =NewRect (); - GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (rect); in         returnRect.top; -}

Android Picture Drag

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.