Reputation: 12201
Motion event can be easily applied by overriding onTouch
inside OnTouchListener
.
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
paramsF.x = initialX + (int)(event.getRawX() - initialTouchX);
paramsF.y = initialY + (int)(event.getRawY() - initialTouchY);
wm.updateViewLayout(view, paramsF);
break;
}
return false;
}
But to apply fling I have to implement the GestureDectector
.
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
How can I implement both fling and ACTION_MOVE
.
Upvotes: 2
Views: 266
Reputation: 12201
Use GestureDectector
after MotionEvent.ACTION_MOVE
will make it work.
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
initialX = paramsF.x;
initialY = paramsF.y;
initialTouchX = event.getRawX();
initialTouchY = event.getRawY();
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
paramsF.x = initialX + (int)(event.getRawX() - initialTouchX);
paramsF.y = initialY + (int)(event.getRawY() - initialTouchY);
mWindowManager.updateViewLayout(v, paramsF);
break;
}
return gestureDetector.onTouchEvent(event);
}
Upvotes: 2