How to do something when user touches canvas? Assistance to check bounds
Hi I drew a bitmap on the canvas and I wanted to do something when the
user touches it.
Bitmap backbutton = BitmapFactory.decodeResource(getResources(),
R.drawable.backbutton);
Paint paint = new Paint();
canvas.drawBitmap(backbutton, canvasWidth - 100, 0, paint);
I have tried the following to solve the problem but it isnt working. How
do I check for inbounds properly?
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();
}
}
But I seem to be doing something wrong with the contains(). Can someone
help me out here please?
No comments:
Post a Comment