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, s...

问题:

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?


回答1:

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.


回答2:

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. For more take a look at Documentation for supporting different pixel densities:

These documents will more help you more further.

https://developer.android.com/studio/write/vector-asset-studio

https://developer.android.com/guide/topics/graphics/vector-drawable-resources


回答3:

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.

  • 发表于 2018-07-05 20:20
  • 阅读 ( 238 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除