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