开发者

implement Canvas in non-Activity class in Android

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. Tha开发者_如何学运维nks


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.


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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜