Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VectorDrawable image becomes pixelated

I've used a couple of images which I've imported using Android Studio's Vector Asset Studio through a local SVG file.

The images loaded perfectly on my nexus 6p, however, on the Sony Xperia Z, its very pixelated, and on Samsung Galaxy s2, its even worse.

From my understanding, since the file is a xml (vector) and not a png file, it should have been able to resize automatically or am I missing out on something.

I've attached an image of the 3 cases. enter image description here

EDIT: Just some extra info: The file was originally a PNG, however, I've fully converted to an vector file using a program called Vector Magic. I can open it on illustrator and edit each line etc.

Solved by changing from VectorDrawable to VectorDrawableCompat through the VectorDrawableCompat.create(..) method. Thanks @pskink.

like image 201
Petersicecream Avatar asked May 17 '16 08:05

Petersicecream


3 Answers

Adding android:scaleType="fitXY" to the image solved it for me.

like image 167
Le-roy Staines Avatar answered Nov 12 '22 08:11

Le-roy Staines


Android supports SVG on API level 21 and higher. For API level 19, 20 it fallback to png generation. The SVG we had put in the app had a smaller size for these generations and hence you seem to get pixelated images on your screen. In my case increasing the

<vector android:height="70dp" android:width="70dp"

of the vector XML generated better png and it started to look better on older devices

like image 27
Vihaan Verma Avatar answered Nov 12 '22 08:11

Vihaan Verma


For me the reason that caused vectors to be converted to png was android:fillType="evenodd" attribute in my vector drawable. When I removed all occurrences of this attribute in my drawable (thus the vector using the default nonzero fill type), next time the app was built everything was fine.

like image 2
Mahozad Avatar answered Nov 12 '22 10:11

Mahozad