Drag any widget with fingers
Asd Code 1
//Create a more block with View:view
_view.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);
_view.setX((int)(StartPT.x+mv.x));
_view.setY((int)(StartPT.y+mv.y));
StartPT = new PointF( _view.getX(), _view.getY() );
break;
case MotionEvent.ACTION_DOWN : DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF( _view.getX(), _view.getY() );
break;
case MotionEvent.ACTION_UP : break;
default : break;
}
return true;
}
});//Create a more block with View:view
_view.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);
_view.setX((int)(StartPT.x+mv.x));
_view.setY((int)(StartPT.y+mv.y));
StartPT = new PointF( _view.getX(), _view.getY() );
break;
case MotionEvent.ACTION_DOWN : DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF( _view.getX(), _view.getY() );
break;
case MotionEvent.ACTION_UP : break;
default : break;
}
return true;
}
});
Post a Comment