Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42670

Should we favor Vector drawable over multiple densities drawable?

It is common that we provides various densities drawables in the project

drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi

I was wondering, should we favor Vector drawable over multiple densities drawable?

I went through https://developer.android.com/training/multiscreen/screendensities#vector-graphics .

But, it doesn't mention when should we use multiple densities drawable, and when should we use Vector drawable. Is there any situation when Vector drawable is not favorable?

Upvotes: 5

Views: 374

Answers (3)

Umair
Umair

Reputation: 6426

According to Android documentation:

An alternative to creating multiple density-specific versions of an image is to create just one vector graphic. Vector graphics create an image using XML to define paths and colors, instead of using pixel bitmaps. As such, vector graphics can scale to any size without scaling artifacts, though they're usually best for illustrations such as icons, not photographs.

So vector drawables are always a better choice then using multiple densities.

This documentation will help you further:

Upvotes: 1

Vahid Amiri
Vahid Amiri

Reputation: 11117

Vector drawables are natively supported in API 21 and up (Android 5) and you won't need to use any special library to be able to use them in your app. For example in the Image tag you can use the src attribute to load vectors just as you would use them to load bitmap images.

They can also be used in older versions of Android with the help of Google support library but there will be a big performance hit.

Upvotes: 1

Udit
Udit

Reputation: 1037

Vector drawables should always be favoured where it is possible to replace the image with a vector as it is completely scalable.

The only place where you would use an image with different densities is when the image cannot be represented by a vector drawable.

Upvotes: 1

Related Questions