Android Support Library 23.2矢量可绘制对象模糊 [英] Android Support Library 23.2 vector drawables are blurry

查看:80
本文介绍了Android Support Library 23.2矢量可绘制对象模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最新版本的Android支持库(23.2)添加了对矢量可绘制对象的支持.似乎是通过在本机不支持矢量可绘制对象的平台上即时对矢量进行栅格化来实现的.

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

布局

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

向量为24dp x 24dp.它用于128dp x 128dp的ImageView中.在不支持矢量可绘制对象的平台上,由于矢量以16dp光栅化并调整为128dp的大小,因此生成的图像模糊.

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.

我发现的唯一解决方案是为每个预期大小创建一个单独的可绘制矢量.创建一堆只改变高度和宽度的重复矢量是很烦人的.如果您希望drawable为fill_parent或以其他方式动态调整大小,那并不能解决问题.

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.

有人能真正解决吗?

推荐答案

向量以16dp栅格化并调整为128dp

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

23.1,Android从提供的VectorDrawable开始创建栅格图像.在支持库的v23.2中已更改了该内容.如果您正确设置build.gradle,则会发生此行为.

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 .

如果您使用的是Gradle Plugin 2.0+,请添加

If you are using the Gradle Plugin 2.0+, add

android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 } 

如果您使用的是1.5.0

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

这篇关于Android Support Library 23.2矢量可绘制对象模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆