Somk
Somk

Reputation: 12047

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.

Upvotes: 0

Views: 300

Answers (2)

didi_X8
didi_X8

Reputation: 5068

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.

Upvotes: 0

jkhouw1
jkhouw1

Reputation: 7350

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/

Upvotes: 2

Related Questions