Support Vector Drawables and Animated Vector Drawables(支持矢量图片和矢量图片动画)
其实前面的文章关于Metarial Design动画中也有介绍到矢量图与矢量图的动画,但是那是局限于5.0以上的设备才可以使用,没想到这么快就Support包就向下支持了。
想在低版本使用还需要做点东西:
AndroidStudio1.4已经引入过矢量绘图支持在构建时生成PNG图像。要想禁用此功能(并想使用最新支持库),你需要在你的build.gradle里面添加vectorDrawables.useSupportLibrary = true
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
你会发现这个新的属性只在AndroidStudio2.0版本存在。如果您使用的是AndroidStudio1.5,需要
// Gradle Plugin 1.5
android {
defaultConfig {
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
遇到问题,使用facebook fresco显示svg矢量图
矢量图ic_xingzuo12.xml
<com.facebook.drawee.view.SimpleDraweeView
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
fresco:actualImageScaleType="none"
fresco:placeholderImage="@drawable/ic_xingzuo12"
fresco:placeholderImageScaleType="fitCenter" />
在比较低的配置手机下,比如:红米1s下,不支持svg显示。
原因
就是parser(解析)布局失败,导致我使用了xutils的@ViewInject,返回的对象全是null。
解决方案
直接使用ImageView显示svg图
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_xingzuo12"/>
补充
查了下,SimpleDraweeView好像不支持API <21的矢量绘图
https://github.com/facebook/fresco/issues/1176
https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88