The latest version of the Android Support Library (23.2) adds support for vector drawables. It appears to do this by rasterizing the vectors on the fly on platforms that don't natively support vector drawables.
However, the rasterize image seems to be a fixed size rather that dependent on usage. Here's an example.
Vector
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zm0,3c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zm0,14.2c-2.5,0 -4.71,-1.28 -6,-3.22 0.03,-1.99 4,-3.08 6,-3.08 1.99,0 5.97,1.09 6,3.08 -1.29,1.94 -3.5,3.22 -6,3.22z"/>
</vector>
Layout
<ImageView
android:layout_width="128dp"
android:layout_height="128dp"
android:id="@+id/imageView"
app:srcCompat="@drawable/vector1"/>
The vector is 24dp x 24dp. It's used in an ImageView that's 128dp x 128dp. On platforms that's don't support vector drawables, the resulting image is blurry because the vector is rasterized at 16dp and resized to 128dp.
The only solution I've found is to create a separate vector drawable for each intended size. It's pretty annoying to create a bunch of duplicate vectors with only the height and width changes. And that doesn't solve the problem if you want the drawable to fill_parent or be dynamically sized in some other way.
Having to define the dimensions of your vector images in advanced almost completely defeats the benefit of using vectors in the first place.
Does anyone have a true work around?
the vector is rasterized at 16dp and resized to 128dp
up to 23.1
, Android was creating raster images starting from the provided VectorDrawable
. This thing changed in v23.2
of the support library. This behavior happens if you set up correctly your build.gradle
.
If you are using the Gradle Plugin 2.0+
, add
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
if you are using 1.5.0
android {
defaultConfig {
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
after you sync, clean your workspace and build again. You can read more about it here and here
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