android view 画线优化

1.在move事件中获取历史所有点,然后绘制
case MotionEvent.ACTION_MOVE:
float x = event.getX();
float y = event.getY();
int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) { float historicalX = event.getHistoricalX(i); float historicalY = event.getHistoricalY(i); float dx = Math.abs(historicalX - mx); float dy = Math.abs(historicalY - my); if (dx >= 2 || dy >= 2) {
trajectory.path.quadTo(mx, my, (historicalX + mx) / 2, (historicalY + my) / 2);//绘制线条轨迹
mx = historicalX;
my = historicalY;
}
}

2.invalidate指定区域:
invalidate(left, top,right,bottom);