开发者

About Android: how to use Log to gain the position (x,y) when I use the onTouchEvent()?

开发者 https://www.devze.com 2023-03-23 09:30 出处:网络
Here is My Code: public boolean onTouchEvent(MotionEvent cv){ int x=(int)cv.getX(开发者_Go百科); int y=(int)cv.getY();

Here is My Code:

 public boolean onTouchEvent(MotionEvent cv){

    int x=(int)cv.getX(开发者_Go百科);
    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:

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

精彩评论

暂无评论...
验证码 换一张
取 消