Image dragable android code

img_id.setOnTouchListener(new OnTouchListener() { PointF DownPT = new PointF(); PointF StartPT = new PointF(); @Override public boolean onTouch(View v, MotionEvent event) { int eid = event.getAction(); switch (eid) { case MotionEvent.ACTION_MOVE : PointF mv = new PointF( event.getX() – DownPT.x, event.getY() – DownPT.y); img_id.setX((int)(StartPT.x+mv.x)); img_id.setY((int)(StartPT.y+mv.y)); StartPT = new PointF( img_id.getX(), img_id.getY() ); break; case MotionEvent.ACTION_DOWN : DownPT.x = event.getX(); DownPT.y = event.getY(); StartPT = new PointF( img_id.getX(), img_id.getY() ); break; case MotionEvent.ACTION_UP : break; default : break; } return true; } });

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.