0
我想創建一個簡單的繪圖應用程序我用戶可以按下我的自定義視圖的一個點,並將其拖動到創建一個矩形或一個圓形,我設法很容易做到這一點。安卓畫布繪製形狀與鬼魂
當我嘗試向用戶展示隨着它變大或變小而移動其形狀的過程中出現問題時。
要簡單地解釋我想作爲Windows一樣的效果,如果你點擊並拖動鼠標在桌面上..
這是我的onTouchEvent方法,我該怎麼做呢?
if (chosenShape.equals("rectangle")) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:// user start pressing
//starting point - one side of the rect
starting_X = touchX;
starting_Y = touchY;
break;
case MotionEvent.ACTION_MOVE:// user move while pressing
break;
case MotionEvent.ACTION_UP:// user release
//ending point - thie side of the circle
ending_X = touchX;
ending_Y = touchY;
// draw the rectangle - opposite side of the rect
drawCanvas.drawRect(starting_X, starting_Y, ending_X, ending_Y, drawPaint);
chosenShape = "";// reseting the shape to keep drawing
break;
default:
return false;
}
} else {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
drawPath.moveTo(touchX, touchY);
break;
case MotionEvent.ACTION_MOVE:
drawPath.lineTo(touchX, touchY);
break;
case MotionEvent.ACTION_UP:
drawCanvas.drawPath(drawPath, drawPaint);
drawPath.reset();
break;
default:
return false;
}
}
我可以存儲這些形狀,但我不能從畫布中刪除它們,我該怎麼做?我如何刷新畫布?你的意思是無效()?因爲那不起作用 –
如果你不能'invalidate()'工作,嘗試調用'canvas.drawColor(Color.TRANSPARENT,Mode.CLEAR);' – ScouseChris