When I create a vector drawable, I can set its size in dp
. The default is 24dp x 24dp.
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).
When a lower API is used and the system scales it down, does the vector size matter?
Do these measurements matter for my use at all, other than just being the default size when I apply wrap_content
?
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.
PathData in vector images android is Vector graphic program's script. It is not exactly clean and human readable code as a high priority.
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.
android:viewportHeight. Used to define the height of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With