gpt4 book ai didi

android - 用润色结束 Canvas

转载 作者:行者123 更新时间:2023-11-29 20:30:50 25 4
gpt4 key购买 nike

我用 Canvas 画线并触摸但我的问题是,当我们再次触摸屏幕时,前面的行被删除了我想再次触摸画新线,但最后一行没有删除发件人 protected void onDraw(Canvas canvas) { super.onDraw( Canvas ); //onDraw时在 Canvas 上用mPaint绘制mPath canvas.drawLine(sX, sY, eX, eY, mPaint);

// when ACTION_DOWN start touch according to the x,y values
private void startTouch(float x, float y) {
sX = x;
sY = y;
}

// when ACTION_MOVE move touch according to the x,y values
private void moveTouch(float x, float y) {
eX = x;
eY = y;
}
private void upTouch(float x, float y) {
eX = x;
eY = y;
}

public void clearCanvas() {
invalidate();
}



@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startTouch(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
moveTouch(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
upTouch(x,y);
invalidate();
break;
}
return true;
}

最佳答案

Here is Canvas 和绘图的一个很好的例子

关于android - 用润色结束 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32016516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com