Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Vector Assets: Do dp measurements only matter for "wrap content"?

Tags:

android

vector

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?

like image 859
Florian Walther Avatar asked Aug 27 '17 01:08

Florian Walther


People also ask

Can vector Drawables be scaled?

In Android 5.0 (API Level 21) and above, you can define vector drawables, which scale without losing definition. Changing the width and height in the definition of the vector drawable to 200dp significantly improves the situation at the 400dp rendered size.

What is Android PathData?

PathData in vector images android is Vector graphic program's script. It is not exactly clean and human readable code as a high priority.

What are vector Drawables in Android?

A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability.

What is viewportHeight Android?

android:viewportHeight. Used to define the height of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.


1 Answers

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

like image 88
Denis Knauer Avatar answered Sep 21 '22 14:09

Denis Knauer