Reputation: 37
All I achieve now is using onTouch(View v, MotionEvent event) event to get the first touch.
But I want to know the x,y values when I continuously drag the mapView.
If anyone knows the answer it would be greatly appreciated.
Upvotes: 0
Views: 168
Reputation: 14472
MotionEvent ACTION_MOVE
http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_MOVE
Tutorial showing how to use it
Upvotes: 1
Reputation: 70
Its pretty straight forward. Here is some code that returns an x & y position of a touch and then returns an angle to rotate an image based on the touch position.
//TouchEvent handler
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d(TAG, "onTouchEvent called...");
x = event.getX();
y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
float dx = x - mPreviousX;
float dy = y - mPreviousY;
//Reverse direction of rotation if above midline
if (y > getHeight() / 2) {
dx = dx * -1;
}
//Reverse direction of rotation if of the midline
if (y < getWidth() / 2) {
dy = dy * -1;
}
Main.mAngle += (dx + dy) * TOUCH_SCALE_FACTOR;
TextView txtView = (TextView) ((Activity)context).findViewById(R.id.mangle);
txtView.setText("Angle: " + String.valueOf(Main.mAngle));
requestRender();
}
mPreviousX = x;
mPreviousY = y;
return true;
}
Upvotes: 1