[英]About Android: how to use Log to gain the position (x,y) when I use the onTouchEvent()?
Here is My Code: 这是我的代码:
public boolean onTouchEvent(MotionEvent cv){
int x=(int)cv.getX();
int y=(int)cv.getY();
// here I want to use Log to gain the position(x,y) that I touched.But how?
if( 0<=y && y<=py ){
if( (px-(py-y)*Math.tan(30))<=x && x<=(px+(py-y)*Math.tan(30)) ){
Log.i(VIEW_LOG_TAG, "yes");
}
}
if( px<=x && x<=(px+py*Math.tan(15)) ){
if( y<=(Math.tan(15)*(px-x)+py) ){
Log.i(VIEW_LOG_TAG, "no");
}
}
return super.onTouchEvent(cv);
}
Log as... android.util.Log ?, if so: 登录为android.util.Log?,如果这样:
Just add: 只需添加:
Log.v(String TAG, String MSG);
Like: 喜欢:
int x=(int)cv.getX();
int y=(int)cv.getY();
// here I want to use Log to gain the position(x,y) that I touched.But how?
Log.v("X", "pos x = " + x);
Log.v("Y", "pos y = " + y);
if( 0<=y && y<=py ){
if( (px-(py-y)*Math.tan(30))<=x && x<=(px+(py-y)*Math.tan(30)) ){
Log.i(VIEW_LOG_TAG, "yes");
}
}
if( px<=x && x<=(px+py*Math.tan(15)) ){
if( y<=(Math.tan(15)*(px-x)+py) ){
Log.i(VIEW_LOG_TAG, "no");
}
}
return super.onTouchEvent(cv);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.