嗨,我在画布上画了一张位图,当用户触摸它时我想做点什么。
Bitmap backbutton = BitmapFactory.decodeResource(getResources(),
R.drawable.backbutton);
Paint paint = new Paint();
canvas.drawBitmap(backbutton, canvasWidth - 100, 0, paint);
我尝试了以下方法来解决问题,但它不起作用。如何正确检查入站?
public void onTouch(View view, MotionEvent event) {
if(backbutton.contains((int) (event.getX()), (int)(event.getY()), (int)(event.getX()+100),(int) (event.getY()+30))) {
Toast.makeText(view.getContext(), "this works", Toast.LENGTH_LONG).show();
}
}
但我似乎对contains()
. 有人可以帮我吗?