Android Canvas didn't draw Path when Path'

2019-04-05 13:50发布

问题:

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?

回答1:

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