我试图做一个应用程序,使用户能够触摸屏幕并根据用户的手指坐标绘制图像。这里是我的代码:安卓绘图触摸事件
public class DrawingBoard extends View {
Drawable editIcon = getResources().getDrawable(R.drawable.icon);
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
float xPos = 0;
float yPos = 0;
public DrawingBoard (Context context) {
// TODO Auto-generated constructor stub
super (context);
}
@Override
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.drawBitmap(mBitmap, 0, 0, null);
canvas.translate(xPos, yPos);
editIcon.draw(canvas);
canvas.restore();
invalidate();
}
@Override
public boolean onTouchEvent (MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN :
xPos = event.getX();
yPos = event.getY();
break;
}
return true;
}
}
}
但是,每当我试图点击模拟器的屏幕上,没有显示图像....
请指出我的错误... THX
invalidate()
这是什么问题与谷歌地图办?? –@SimonAndréForsberg老兄,为什么你放弃这个答案的投票。你做了什么?你看不到。此代码将通过Google地图在触摸事件上绘制图像。我不知道你有什么问题。如果你不明白,那就给我一个机会,我会详细说明它。 –