只需使用:
event.getRawX();
event.getRawY();
導致屏幕座標,
開始0,0
(左上角)
到width,height
(右下角)
取決於設備,但我認爲那對你來說並不陌生;)
--- ---更新
我想我已經missunderstood你,對不起 ..
那就試試這個:
int saved_x = -1;
int saved_y = -1;
@Override
public boolean onTouchEvent(MotionEvent event)
{
final int action = event.getAction();
final int pointer_index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
int pid = event.getPointerId(pointer_index);
int x = (int)event.getX();
int y = (int)event.getY();
switch (action & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
saved_x = x;
saved_y = y;
break;
case MotionEvent.ACTION_MOVE:
int relative_x = x - saved_x;
int relative_y = y - saved_y;
//move right --> relative_x increases by 'm' pixels of movement
//move left --> relative_x decreases by 'm' pixels of movement
//move down --> relative_y increases by 'm' pixels of movement
//move up --> relative_y decreases by 'm' pixels of movement
//use it :D
break;
case MotionEvent.ACTION_UP:
saved_x = -1; //-1 indicates "no finger on screen" -- just a feature :)
saved_y = -1; //-1 indicates "no finger on screen" -- just a feature :)
break;
}
return true;
}
我希望這是你現在想要什麼:)
但我希望我的「錨點」(0,0)從我觸摸的位置(ACTION_DOWN)開始,而不是從左上角開始。然後從我開始的那個點開始逐漸增加或減少。 –
- 更新後 - – bricklore
工作完美!非常感謝! –