level 8
金士顿070
楼主
但是手指按下向左向上滑动, 就不能实时显示画的矩形,要等手松开后才显示画的矩形,这是什么原因呢
/**
* 初始化
*/
private void init() {
mCanvas = new Canvas();
creatNewPen();
DisplayMetrics metrics=getResources().getDisplayMetrics();
mBitmap = Bitmap.createBitmap(metrics.widthPixels,
metrics.heightPixels, Bitmap.Config.ARGB_8888);
mCanvas.setBitmap(mBitmap);
}
private void creatNewPen() {
mysquare = new Mysquare(10, Color.RED);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
isTouch = false;
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mCanvas.setBitmap(mBitmap);
creatNewPen();
mysquare.touchDown(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
mysquare.touchMove(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
mysquare.touchUp(x, y);
mysquare.draw(mCanvas);
invalidate();
isTouch = true;
break;
}
return true;
}
@Override
protected void onDraw(Canvas canvas) {
if (mBitmap != null) {
canvas.drawBitmap(mBitmap, 0, 0, null);
}
if (null != mysquare) {
if (!isTouch) { //调用绘图功能
mysquare.draw(canvas);
}
}
}
2016年05月07日 08点05分
1
/**
* 初始化
*/
private void init() {
mCanvas = new Canvas();
creatNewPen();
DisplayMetrics metrics=getResources().getDisplayMetrics();
mBitmap = Bitmap.createBitmap(metrics.widthPixels,
metrics.heightPixels, Bitmap.Config.ARGB_8888);
mCanvas.setBitmap(mBitmap);
}
private void creatNewPen() {
mysquare = new Mysquare(10, Color.RED);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
isTouch = false;
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mCanvas.setBitmap(mBitmap);
creatNewPen();
mysquare.touchDown(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
mysquare.touchMove(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
mysquare.touchUp(x, y);
mysquare.draw(mCanvas);
invalidate();
isTouch = true;
break;
}
return true;
}
@Override
protected void onDraw(Canvas canvas) {
if (mBitmap != null) {
canvas.drawBitmap(mBitmap, 0, 0, null);
}
if (null != mysquare) {
if (!isTouch) { //调用绘图功能
mysquare.draw(canvas);
}
}
}