Android开发 之 矢量图的兼容问题
来源:互联网 发布:mac air 13寸 长宽 编辑:程序博客网 时间:2024/06/05 06:38
矢量图的兼容问题
在支持平台版本低于Android 5.0(API级别21)的设备上支持向量可绘制和动画向量绘制,VectorDrawableCompat和AnimatedVectorDrawableCompat可通过两个新的支持库分别提供:support-vector-drawable和animated-vector-drawable。
Android Studio 1.4通过在构建时生成PNG文件,为矢量绘图提供了有限的兼容性支持。 然而,矢量可绘制和动画矢量绘制支持库提供了灵活性和广泛的兼容性 - 它是一个支持库,因此您可以将其与所有Android平台版本一起使用到Android 2.1(API级别为7+)。要将应用程序配置为使用向量支持库,请将vectorDrawables元素添加到应用程序模块中的build.gradle文件中。
使用以下代码片段来配置vectorDrawables元素:
//For Gradle Plugin 2.0+ android { defaultConfig { vectorDrawables.useSupportLibrary = true } }
//For Gradle Plugin 1.5 or belowandroid { defaultConfig { // Stops the Gradle plugin’s automatic rasterization of vectors generatedDensities = [] } // Flag notifies aapt to keep the attribute IDs around aaptOptions { additionalParameters "--no-version-vectors" }}
当然还要导入支持包:
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-vector-drawable:25.3.0'
同时,确保你使用的是AppCompatActivity而不是普通的Activity。
当您使用ImageView或者ImageButton和FloatingActionButton等子类使用android.support.v7.appcompat包时,您可以使用新的应用:srcCompat属性来引用矢量绘图以及任何其他可用的android:src:
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/ic_add" />
要在运行时更改drawables,可以像以前一样使用setImageResource()方法。
但是当你在低版本使用这些组件的话强烈建议使用支持包中的组件。以免不需要的麻烦出现
VectorDrawableCompat vectorDrawableCompat = VectorDrawableCompat.create(getResources(), R.drawable.ic_dahai01, null); imageView.setImageDrawable(vectorDrawableCompat);
AnimatedVectorDrawableCompat animatedVectorDrawableCompat1 = AnimatedVectorDrawableCompat.create(this, R.drawable.av_yun);iv_yunduo.setImageDrawable(animatedVectorDrawableCompat1);animatedVectorDrawableCompat1.start();如果矢量图用于选择器的话需要特别注意:
在activity中添加一下代码:
static { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);}你就可以正常使用Selector这样的DrawableContainers了。同时,你还开启了类似android:drawableLeft这样的compound drawable的使用权限,以及RadioButton的使用权限,以及ImageView’s src属性。
当然在高系统版本的是时候就不要使用兼容包了,判断版本走不通的代码,因为手机品牌太多了坑太多了,我就遇见过,使用兼容包在不通的手机上出问题。
兼容包不支持路径变换,在低版本手机上没有效果而且还报错。其他方面基本支持。
关于path路径自己用代码绘制的话会死人的,不想死就用下面的或者AI软件
http://editor.method.ac/
http://inloop.github.io/svg2android/
阅读全文
0 0
- Android开发 之 矢量图的兼容问题
- Android开发 之 矢量图及其动画
- QGIS开发之矢量图层的使用
- Android 开发之API兼容问题
- Android 开发之API兼容问题
- Android 开发之API兼容问题
- Android 开发之API兼容问题
- Android 开发之API兼容问题
- Android开发 之 矢量图动画SVG(细节版)
- android 矢量图的打造
- Android矢量图的制作
- Android开发中使用矢量图
- android开发游记:VectorDrawable矢量图兼容性问题的解决方案
- android矢量图之VectorDrawable ,自由又方便的填充色彩
- Android的Vector矢量图绘制
- Android05--Android之Drawable的着色兼容问题
- Android 开发兼容问题汇总
- ArcEngine开发之矢量图层渲染实现
- MySQL 表分区
- C++
- 21天学通python——第二天
- css cursor鼠标指针光标样式default pointer hand url
- n-queens
- Android开发 之 矢量图的兼容问题
- 苹果发布全新旗舰,对国内手机市场将造成什么影响?
- UOJ 264 NOIP2016 DAY2 T2 浅谈队列单调性及辅助队列时间戳
- [LintCode]172.删除元素
- PHP微信支付开发过程,分享给大家;供参考
- #!/bin/bash和#!/bin/sh
- Sublime Text3 3143 以前注册码失效的问题
- scala-1
- libevent数据结构-TAILQ_QUEUE队列