[英]Mapping event.getRawX() and event.getX()
我正在開發繪圖應用程序,正在使用event.getRawX()
獲取屏幕觸摸信息。我想要在Android canvas繪制區域中正確映射event.getRawX()
和event.getX()
,如何實現這一目標?
嘗試做這樣的事情
public boolean onTouch(final View v, final MotionEvent event) {
int rawXCord, rawYCord;
final int actionIndex = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
final int location[] = { 0, 0 };
v.getLocationOnScreen(location);
rawXCord= (int) event.getX(actionIndex) + location[0];
rawYCord= (int) event.getY(actionIndex) + location[1];
//do ahead accordingly
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.