private float PRESS_LEVEL = 16.5f; info: class PathInfo{ Path path; Rect rect; int color; float press; public PathInfo(Path pth, Rect rc, float prss){ path = pth; rect = new Rect(rc); color = GlobalSetting.mScriptColor; press = prss; } public PathInfo(Path pth, int left, int top, int right, int bottom){ path = pth; rect = new Rect(left, top, right, bottom); } } paint初始化: List<PathInfo> mPathInfo = new ArrayList<PathInfo>(); mPath = new Path(); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeWidth(GlobalSetting.mScriptWidth); mPaint.setColor(...); onDraw绘制: PathInfo pathInfo; for (int i = 0; i < mPathInfo.size(); i++){ pathInfo = mPathInfo.get(i); if (Rect.intersects(r, pathInfo.rect)){ mPaint.setColor(pathInfo.color); //press mPaint.setStrokeWidth(pathInfo.press); //press over } canvas.drawPath(pathInfo.path, mPaint); } down: mCurX = (int)event.getX(); mCurY = (int)event.getY(); mPrevX = mCurX; mPrevY = mCurY; //press float pressD = event.getPressure(); float width = getEventPress(pressD); mPaint.setStrokeWidth(width); mPath = new Path(); mPath.moveTo(mCurX, mCurY); PathInfo pathInfoH = new PathInfo(mPath, mRect, width); mPathInfo.add(pathInfoH); mPrePress = width; move: for (i=0; i<N; i++) { x = (int)event.getHistoricalX(i); y = (int)event.getHistoricalY(i); //press pressH =event.getHistoricalPressure(i); float width = getEventPress(pressH); mPath = new Path(); mPaint.setStrokeWidth(width-i); drawPoint(mCurX, mCurY, x, y); PathInfo pathInfoH = new PathInfo(mPath, mRect, width); mPathInfo.add(pathInfoH); mCurX = x; mCurY = y; mPrePress = width; } point 绘制: private void drawPoint(int x1, int y1, int x2, int y2){ mPath.moveTo(mPrevX, mPrevY); mPath.quadTo(x1, y1, (x1+x2)/2, (y1+y2)/2); mPrevX = (x1+x2)/2; mPrevY = (y1+y2)/2; } 获取width: private float getEventPress(float press){ //0.05~0.25,normal 0.15 float width = GlobalSetting.mScriptWidth +(press*100-(float)PRESS_LEVEL); Log.i(TAG,"press:"+press+",width:"+width); return width; } 实现apidemos中的笔迹绘制,但是压感的公式需要调整。