AppCompat v23.2 ---关于Vector

我们都知道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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值