-1
我想檢查觸摸x,y position
在我的activity
知道它是否我的RelativeLayout
或不。 我重寫了onTouch
活動的活動,但它不能正常工作。檢查觸摸的相對佈局
我想檢查觸摸x,y position
在我的activity
知道它是否我的RelativeLayout
或不。 我重寫了onTouch
活動的活動,但它不能正常工作。檢查觸摸的相對佈局
你必須做這樣的事情。在Activity
你必須覆蓋
dispatchTouchEvent
所以在你的onCreate
找到你的看法
RelativeLayout yourLayout = (RelativeLayout) findViewById(R.id.yourLayout);
然後
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
float touchPointX = ev.getX();
float touchPointY = ev.getY();
int[] coordinates = new int[2];
yourLayout.getLocationOnScreen(coordinates);
if (touchPointX < coordinates[0] || touchPointX > coordinates[0] + yourLayout.getWidth() || touchPointY < coordinates[1] || touchPointY > coordinates[1] + yourLayout.getHeight()){
//Do Your ACTION
}
return super.dispatchTouchEvent(ev);
}