I am attempting to use vector drawables in my Android app. From http://developer.android.com/training/material/drawables.html (emphasis mine):
In And
1) Why is there a width/height specification in the vector drawable? I thought the entire point of these is that they scale up and down losslessly making width and height meaningless in its definition?
For SDK versions less than 21 where the build system needs to generate raster images and as the default size in cases where you don't specify the width/height.
2) Is it possible to use a single vector drawable which works as a 24dp drawable on a TextView as well as a large near-screen width image?
I don't believe this is possible if you also need to target SDKs less than 21.
3) How do I effectively use the width/height attributes and what is the difference with viewportWidth/Height?
Documentation: (actually not very useful now that I re-read it...)
android:width
Used to define the intrinsic width of the drawable. This support all the dimension units, normally specified with dp.
android:height
Used to define the intrinsic height the drawable. This support all the dimension units, normally specified with dp.
android:viewportWidth
Used to define the width of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.
android:viewportHeight
Used to define the height of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.
More documentation:
Android 4.4 (API level 20) and lower doesn't support vector drawables. If your minimum API level is set at one of these API levels, Vector Asset Studio also directs Gradle to generate raster images of the vector drawable for backward-compatibility. You can refer to vector assets as
Drawable
in Java code or@drawable
in XML code; when your app runs, the corresponding vector or raster image displays automatically depending on the API level.
Edit: Something weird is going on. Here's my results in the emulator SDK version 23 (Lollipop+ test device is dead right now...):
And in the emulator SDK version 21: