开发者

Canvas vs Image Android

I have a background image that is white and semi-transparent. This is used as a text container so you can differentiate between the background image and text.

Currently I am using an image that is a white rectangle with rounded corners, but of course when using this on different screen sizes the image is distorted, not massively or that noticeably, but would it be better or possible to draw this image with a canvas?

If it is possible would it slow down the app considerably?

UPDATE:

Thank you @jkhouw1 I have looked into 9 patch images and this seems very suitable开发者_开发知识库. I am still interested in knowing the benefit of canvas against images, but if you post something as an answer I will accept it. Thank you.


use a nine patch is a graphic that android can scale appropriately. see here: http://developer.android.com/guide/developing/tools/draw9patch.html

and here http://www.higherpass.com/Android/Tutorials/Android-9-Patch-Scaled-Png-Image-Guide/


Haven't tried this yet, but I think this should be possible by defining a shape drawable. You can define round corners and you can make it semi-transparent by defining the color with alpha-value, for example #80FF0000 should be semi-transparent red.
I assume this would be a good solution both in terms of compatibility and performance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜