1

I have a canvas and I am drawing bitmap into it and moving that bitmap using onTouchEvent method. My problem is that the bitmap I move sometimes go out of the canvas region so how to solve this problem related to boundry of canvas. Please help me out on this and Thanks in advance.

robertc
  • 74,533
  • 18
  • 193
  • 177
Rocker
  • 669
  • 5
  • 15

2 Answers2

1

When you move the finger over the screen, you set the x,y drawing coordinates for your bitmap. Since you can know the size of the canvas from onSizeChanged method, you just need to make an if statement which will change the drawing coordinates of this bitmap only if the finger is within the area you want.

Lumis
  • 21,517
  • 8
  • 63
  • 67
  • Thanks for your answer but I can't find onSizeChanged method on Android Developer site. Could you please give the link where I can study about onSizeChanged method. – Rocker Oct 12 '11 at 11:04
  • Check these examples: http://stackoverflow.com/questions/4938822/how-can-i-use-the-animation-framework-inside-the-canvas/4946893#4946893 – Lumis Oct 12 '11 at 12:44
0

From the distance of current position and the base position calculate from your algorithm, you could able to manage this problem. It's only your algorithm problem.

Dat Tran
  • 136
  • 1
  • 10