Support Android Support 23.2 Vector Drawings Blurred

The latest version of Android Support Library (23.2) added support for vector drawings. This seems to be happening by rasterizing vectors on the fly on platforms that don't support vector drawings.

However, the rasterized image seems fixed, depending on usage. Here is 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> 

Markup

 <ImageView android:layout_width="128dp" android:layout_height="128dp" android:id="@+id/imageView" app:srcCompat="@drawable/vector1"/> 

Vector 24dp x 24dp. It is used in ImageView, 128dp x 128dp. On platforms that do not support vector drawings, the resulting image is blurry because the vector is rasterized at 16dp and changed to 128dp.

The only solution I found was to create a separate vector suitable for each size. It is quite annoying to create a bunch of repeating vectors with changes in height and width. And this does not solve the problem if you want drawable for fill_parent or be dynamically defined in some other way.

To determine the size of your vector images in advanced, almost completely astonishes the advantage of using vectors in the first place.

Does anyone have a true job?

+11
source share
2 answers

the vector is rasterized at 16dp and changes to 128dp

23.1 to 23.1 , Android created bitmaps starting with the one provided by VectorDrawable . This has changed in the v23.2 support library. This happens if you configured your build.gradle .

If you are using Gradle Plugin 2.0+ , add

 android { defaultConfig { vectorDrawables.useSupportLibrary = true } } 

if you use 1.5.0

  android { defaultConfig { generatedDensities = [] } // This is handled for you by the 2.0+ Gradle Plugin aaptOptions { additionalParameters "--no-version-vectors" } } 

after synchronization, cleaning the workspace and assembly again. You can read about it here and here.

+16
source

enlarge Android: width, height in your XML.

 <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" 

After I increased the size, the generated png size also increased, and the images stopped looking blurry.

+2
source

All Articles