13

When I create a vector drawable, I can set its size in dp. The default is 24dp x 24dp.

  1. Do these measurements matter in terms of performance if I use the vector in a different size than 24dp x 24dp in my app? Also in regards of API under 21 (I use app:srcCompat to show the images).

  2. When a lower API is used and the system scales it down, does the vector size matter?

  3. Do these measurements matter for my use at all, other than just being the default size when I apply wrap_content?

Sky Kelsey
  • 19,192
  • 5
  • 36
  • 77
Florian Walther
  • 6,237
  • 5
  • 46
  • 104

2 Answers2

1

I probably cannot answer all your questions but the DP size matters for sure if you are not using vector drawables through Support library on pre-Lollipop versions.

To enable the support vector drawables you must add the following to your apps's gradle build file:

android {  
    defaultConfig {  
        vectorDrawables.useSupportLibrary = true  
    }  
}

See https://android-developers.googleblog.com/2016/02/android-support-library-232.html

If this is not part of your app's build file Android Studio will generate PNGs for all pre-Lollipop versions which will have the defined DP size. So if your vector defines 24dp and you are using it as 128dp graphic, it will most likely not look very good on pre-Lollipop versions as an 24dp PNG will be used.

The generated PNGs can be found here:

app\build\generated\res\pngs\...

The otherway around if your vector is 128dp and you are using it as 24dp graphic the scaled down PNG graphic might also not look as perfect as expected due to the scaling and you are probably wasting some file size due to too large PNGs.

I never actually looked at what that means for the performance...

Denis Knauer
  • 1,020
  • 9
  • 18
  • Yes of course. I hadn't thought of the fallback PNG generation. So essentially, if you are using a vector drawable without PNG fallback, the dimensions in the drawable XML only matter if you are using `wrap_content`. Thanks! – Sky Kelsey Oct 26 '17 at 18:08
0
  1. When you are using wrap_content, then device will render vector in your desired size (24dp). Setting bigger size will result in bigger bitmap being rendered, that affects your UI and performance. If your are not using wrap content and you are using support library for vectors, than vector size shouldn't matter.
  2. If you set vectorDrawables.useSupportLibrary = false, then your apk will contain also generated bitmaps of vectors used for devices bellow API 21. Bigger bitmaps needs more time to open, uses more memory and also increases the size of your apk. If you use bigger size than needed for your UI (system will scale it down), it will also affect performance and possibly can decrease image quality.
  3. Answered in #1, when you are not using wrap_content, size shouldn't matter if you are using vectorDrawables.useSupportLibrary = true
Milos Fec
  • 828
  • 6
  • 11