我正在使用surfaceview在屏幕上绘制位图现在我想在点击/触摸位图时将其从屏幕上删除。我怎么能这样做。
答案 0 :(得分:0)
将此添加到mainActivity以获取触摸坐标:
(...)
int touchX, touchY;
boolean touch = false;
@Override
public boolean onTouchEvent (MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_UP)
{
touchX = (int) event.getX();
touchY = (int) event.getY();
touch = true;
}
return false;
}
(...)
并将其用于您的位图:
(...)
if(mainActivity.touch)
{
if( (mainActivity.touchX > bitmapX) && (mainActivity.touchX < bitmapX + bitmapWidth) && //
(mainActivity.touchY > bitmapY) && (mainActivity.touchY < bitmapY + bitmapHeight) ) //touch detection for your bitmap
{
bitmap.recycle(); //I think this is what you want
}
}
if(!bitmap.isRecycled()) //using a recycled bitmap will cause an error
{
yourCanvas.drawBitmap(...);
}
(...)