1

I am working on a project that extends the Map Activity class once.This project can only have this one activity.

I would like to implement the Canvas however since from my knowledge it depends on the Activity class, this has proven to be a road block.

My query is how can I bypass this issue? Is there a way I can actually draw on a canvas minus the Activity class? Any ideas would be gladly welcome. Thanks

hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
user788511
  • 1,726
  • 2
  • 30
  • 52

2 Answers2

0

You can get an instance of Canvas like this:

Paint p = new Paint(); 
...
Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawArc(new RectF(10, 10, 90, 90), 0, 270, false, p);

I use this snippet in a BroadcastReceiver that is not an Activity and you can see that I draw on it.

hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
0

Why you want to use Canvas ?

If you are using Mapactivity then you must be using MapView, so you can draw anything on MapView using Map Overlay Method..

You can draw everything on map like as Line, Circle, Image...etc

Here is simple example of how to overlay on MapView

1.Example

2.Example

3.Example

you can also user onTouch Method for draw..

Community
  • 1
  • 1
Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
  • Thanks CapDroid. The reason I must use the canvas is because I am implementing it outside the main MapActivity class. Can this be done? – user788511 Aug 26 '11 at 06:34