WEB开发网
开发学院手机开发Android 开发 Android获取屏幕触摸坐标 阅读

Android获取屏幕触摸坐标

 2010-06-04 03:04:00 来源:WEB开发网   
核心提示:public boolean onTouchEvent(MotionEvent event) {int action = event.getAction();mCurDown = action == MotionEvent.ACTION_DOWN|| action == MotionEvent.ACTION_MOVE;

public boolean onTouchEvent(MotionEvent event) {

int action = event.getAction();

mCurDown = action == MotionEvent.ACTION_DOWN

|| action == MotionEvent.ACTION_MOVE;

int N = event.getHistorySize();

for (int i=0; i< i++)>

//Log.i("TouchPaint", "Intermediate pointer #" + i);

drawPoint(event.getHistoricalX(i), event.getHistoricalY(i),

event.getHistoricalPressure(i),

event.getHistoricalSize(i));

}

drawPoint(event.getX(), event.getY(), event.getPressure(),

event.getSize());

return true;

}

private void drawPoint(float x, float y, float pressure, float size) {

//Log.i("TouchPaint", "Drawing: " + x + "x" + y + " p="

// + pressure + " s=" + size);

mCurX = (int)x;

mCurY = (int)y;

mCurPressure = pressure;

mCurSize = size;

mCurWidth = (int)(mCurSize*(getWidth()/3));

if (mCurWidth < 1) mCurWidth = 1;

if (mCurDown && mBitmap != null) {

int pressureLevel = (int)(mCurPressure*255);

mPaint.setARGB(pressureLevel, 255, 255, 255);

mCanvas.drawCircle(mCurX, mCurY, mCurWidth, mPaint);

mRect.set(mCurX-mCurWidth-2, mCurY-mCurWidth-2,

mCurX+mCurWidth+2, mCurY+mCurWidth+2);

invalidate(mRect);

}

mFadeSteps = 0;

}

Tags:Android 获取 屏幕

编辑录入:coldstar [复制链接] [打 印]
赞助商链接