APP开发实战95-动态Vector基础
来源:互联网 发布:海量数据的处理 编辑:程序博客网 时间:2024/06/05 07:47
24.5Vector动态图的使用
24.5.1动态Vector基础
动态的Vector需要通过animated-vector标签来进行实现,它就像一个粘合剂,将控件与Vector图像粘合在了一起,一个基础的animated-vector代码如下所示:
<?xmlversion="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector_drawable">
<target
android:name="star"
android:animation="@animator/star_anim" />
</animated-vector>
目标图像是drawable//vector_drawable,name属性,就是在静态Vector图像中group或者path标签的name属性。
目标图像:
<vectorxmlns:android="http://schemas.android.com/apk/res/android"
android:width="500px"
android:height="500px"
android:viewportHeight="500"
android:viewportWidth="500">
<group
android:name="star_group"
android:scaleX="5.0"
android:scaleY="5.0">
<path
android:name="star"
android:pathData="M50.0,90.0 L 82.9193546357,27.2774101308 L 12.5993502926,35.8158045183 L59.5726265715,88.837672697 L 76.5249063296,20.0595700732 L10.2916450361,45.1785327898 L 68.5889268818,85.4182410261 L68.5889268818,14.5817589739 L 10.2916450361,54.8214672102 L76.5249063296,79.9404299268 L 59.5726265715,11.162327303 L12.5993502926,64.1841954817 L 82.9193546357,72.7225898692 L 50.0,10.0 L17.0806453643,72.7225898692 L 87.4006497074,64.1841954817 L40.4273734285,11.162327303 L 23.4750936704,79.9404299268 L89.7083549639,54.8214672102 L 31.4110731182,14.5817589739 L31.4110731182,85.4182410261 L 89.7083549639,45.1785327898 L23.4750936704,20.0595700732 L 40.4273734285,88.837672697 L87.4006497074,35.8158045183 L 17.0806453643,27.2774101308 L 50.0,90.0Z"
android:strokeColor="@color/colorAccent"
android:strokeWidth="2" />
</group>
</vector>
这里的Vector图像比之前的要多了一个group标签。group标签的作用有两个:
对Path进行分组,由于后面需要针对Path进行动画,所以可以让具有同样动画效果的Path在同一个Group中
拓展动画效果,单个的path标签是没有translateX和translateY属性的,因此无法使用属性动画来控制pathtranslateY,而group标签是有的,所以我们需要先将相关的path标签元素包裹在一个个的group标签中。
动画效果star_anim.xml,就是基础的属性动画:
<?xmlversion="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="5000"
android:propertyName="trimPathStart"
android:repeatCount="infinite"
android:repeatMode="restart"
android:valueFrom="1"
android:valueTo="0"/>
<objectAnimator
android:duration="5000"
android:propertyName="strokeColor"
android:repeatCount="infinite"
android:repeatMode="restart"
android:valueFrom="@color/colorAccent"
android:valueTo="@color/colorPrimaryDark" />
</set>
在代码中使用:
ImageViewimageView = (ImageView) findViewById(R.id.image_view);
Drawable drawable = imageView.getDrawable();
//AnimatedVectorDrawableCompat实现了Animatable接口
if (drawable instanceof Animatable){
((Animatable) drawable).start();
}
参考;http://blog.csdn.net/eclipsexys/article/details/51838119
- APP开发实战95-动态Vector基础
- APP开发实战96-动态Vector兼容性问题
- APP开发实战91-静态Vector基础
- APP开发实战92-静态Vector兼容性处理
- APP开发实战93-静态Vector语法简介
- APP开发实战94-Vector静态图的使用
- APP开发实战82-Android动态权限申请
- APP开发实战83-Android动态权限兼容性问题
- Hybrid App开发实战
- hybrid app开发实战
- Hybrid App开发实战
- Hybrid App开发实战
- Hybrid App开发实战
- iPhone App开发实战手册
- APP开发实战68-IntentService
- APP开发实战73-BroadcastReceiver
- APP开发实战51-APP架构设计
- APP开发实战117-APP图片优化
- 那些年搞不懂的高深术语——依赖倒置•控制反转•依赖注入•面向接口编程
- 相机姿态估计
- Kafka集群Leader均衡(Balancing leadership)
- LeetCode 26. Remove Duplicates from Sorted Array
- Android中加入百度地图
- APP开发实战95-动态Vector基础
- iOS 属性修饰符的区别
- 2016.7.17比赛 总结
- 管道
- Kafka日志删除源码分析
- Xcode开发学习:入门1
- 汉字转拼音工具类
- 如何生成一个arff文件
- Kafka Producer是如何动态感知Topic分区数变化