-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);
}