0
我想繪製android.But線,但我不滿足,因爲它不繪製完整線,它繪製一條虛線,當我快速移動對象,並繪製完整的線時我謹對象slowly.Plaese幫我爲什麼這個happenes.I只想完整產品線不虛line.My代碼是在這裏: 上的觀點觸摸事件:使用drawPoint()的繪製線
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
_xDelta = X - lParams.leftMargin;
Log.e("ACTION DOWN X", "" + Y + "---" + lParams.leftMargin);
_yDelta = Y - lParams.topMargin;
Log.e("ACTION DOWN Y", "" + Y + "---" + lParams.leftMargin);
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
layoutParams.leftMargin = X - _xDelta;
Log.e("ACTION Move left margin", "" + (X - _xDelta));
layoutParams.topMargin = Y - _yDelta;
Log.e("ACTION Move top margin", "" + (Y - _yDelta));
layoutParams.rightMargin = -250;
layoutParams.bottomMargin = -250;
view.setBackgroundColor(random.nextInt());
view.setLayoutParams(layoutParams);
draw = new DrawLine(MainActivity.this, X - _xDelta, Y - _yDelta);
root.addView(draw);
break;
}
root.invalidate();
return true;
}
而我的畫法是這樣的:
@Override
protected void onDraw(final Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
// paint.setColor(random.nextInt());
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(4);
canvas.drawPoint(startX, startY, paint);
}
而且我也想知道如何清除所有繪圖。
請幫我解決這個問題。 謝謝。