AppCompat v23.2 ---关于Vector

来源:互联网 发布:python 相关性分析 编辑:程序博客网 时间:2024/05/17 05:04

我们都知道AppCompat 23.2.0近期已经发布,如果你还不知道------http://android-developers.blogspot.com/2016/02/android-support-library-232.html

关于23.2.0这个版本其他的内容就不说了,这里着重了解下Vector drawable(这个本身是SDK 21之后才有的)。

Support包中对应的是VectorDrawableCompat和Animated VectorDrawableCompat。

配置Gradle:

VectorDrawableCompat依赖于AAPT,如果你在Gradle 插件v2.0+:

android {  defaultConfig {    vectorDrawables.useSupportLibrary = true  }}
如果你是v1.5:

android {  defaultConfig {    // Stops the Gradle plugin’s automatic rasterization of vectors    generatedDensities = []  }  // Flag to tell aapt to keep the attribute ids around  aaptOptions {    additionalParameters "--no-version-vectors"  }}
如果你有用nuwa热修复的话,gradle会报错(目前估计只能等nuwa升级版本)。

使用:

res/drawable/ic_search.xml

<vector xmlns:android="..."        android:width="24dp"        android:height="24dp"        android:viewportWidth="24.0"        android:viewportHeight="24.0"        android:tint="?attr/colorControlNormal">    <path        android:pathData="..."        android:fillColor="@android:color/white"/></vector>
ImageView: 此处用app:srcCompat

<ImageView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    app:srcCompat="@drawable/ic_search"/>

代码:

ImageView iv = (ImageView) findViewById(...);iv.setImageResource(R.drawable.ic_search);

有趣的方式:

写一个selector:

<selector xmlns:android="...">    <item android:state_checked="true"               android:drawable="@drawable/checked_icon" />    <item android:drawable="@drawable/icon" /></selector>
这样你在其他地方就跟以前使用一样了

TextView:

<TextView    android:drawableLeft="@drawable/state_list_icon" />
RadioButton:

<RadioButton    android:button="@drawable/state_list_icon" />
ImageView:

<ImageView    android:src="@drawable/state_list_icon" />
实际上其他类型的Drawable也可以  比如InsetDrawable,LayerDrawable等,只是这种方法比较绕,你需要先创建一个文件。

动画Vecotor

只支持Api v11+,在这之前的系统会返回null或者什么也不显示。

当Api 小于v21,下面这些内容也不能用:

1.路径渐变:从一个路径渐变到另外一个路径。

2.路径插值:用于定义个动态的interporlator来代替系统默认的比如LinearInterporlator。

3.沿着路径移动:很少使用不介绍。

总的来说动画vector还是依赖于平台。











0 0