Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Canvas didn't draw Path when Path's point out of view

I ran into some problem with Android Canvas when drawing path. My case is that i have a relative layout work like a map view ( not using google api or something like that ). I have to draw a path onto that view.

    canvas.drawPath(polyPath, borderPaint);

I also have to draw other type like circle, polygon using canvas as well. Everytime we zoom in or zoom out, we re-calculate path point to match with zoom level. When using old api like android 2.3.3, there no problem at all. But for newer api like android 4.x, when we zoom in, there are point which have position out of visible view ( like -300,-300 for example ). After a while zoom in, the visible area only display a small part of my path. And then suddenly the whole path disappear. If we zoom out, it appear again. It like canvas stop rendering those ( other object still display like icon ) Same thing go for circle, oval or polygon.

So i'm not sure if there any change in how canvas draw thing ? Is there anything i'm missing about drawing using canvas?

like image 955
mameo Avatar asked Oct 29 '13 05:10

mameo


1 Answers

Add this line in the initialization of the view

setLayerType(View.LAYER_TYPE_SOFTWARE, null);

also see this guide for hardware level supported API

google API

Img A

Img B

like image 54
Ali Imran Avatar answered Oct 04 '22 21:10

Ali Imran