VectorDrawable(三)
来源:互联网 发布:windows 组播 编辑:程序博客网 时间:2024/05/17 03:05
前面两篇介绍了VectorDrawable的基本应用和一些属性的介绍,这一篇我们主要介绍AnimatedVectorDrawable,即使用VectorDrawable制作的图片加上一些属性动画,来制作含有动画效果的VectorDrawable。
一般需要四个步骤,如下:
一、创建VectorDrawable图片drawable/vectordrawable.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="64dp" android:width="64dp" android:viewportHeight="600" android:viewportWidth="600" > <group android:name="rotationGroup" android:pivotX="300.0" android:pivotY="300.0" android:rotation="45.0" > <path android:name="v" android:fillColor="#000000" android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" /> </group></vector>
创建一个名为rotationGroup的group在其中画了一个三角形的patch,名为v,并将其顺时针旋转45度(android:rotation=”45.0”)
二、创建动画文件anim/rotation.xml :
<set xmlns:android="http://schemas.android.com/apk/res/android"><objectAnimator android:duration="6000" android:propertyName="rotation" android:valueFrom="0" android:valueTo="360" android:repeatCount="infinite" android:repeatMode="reverse" /></set>
android:duration持续时间6s
android:valueFrom=”0” android:valueTo=”360” 从0旋转到3600度
android:repeatCount=”infinite”重复次数无限次
android:repeatMode=”reverse”重复模式反向
anim/path_morph.xml :
<set xmlns:android="http://schemas.android.com/apk/res/android"> <objectAnimator android:duration="6000" android:propertyName="pathData" android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z" android:valueTo="M300,70 l 0,-70 70,0 0,140 -70,0 z" android:valueType="pathType" android:repeatCount="infinite" android:repeatMode="reverse" /></set>
三、创建一个文件将动画和drawable连接起来drawable/avd.xml :
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" //对应的drawable文件 android:drawable="@drawable/vectordrawable" > <target //将drawable下的rotationGroup和rotation关联 android:name="rotationGroup" android:animation="@anim/rotation" /> <target //将drawable下的v和path_morph关联 android:name="v" android:animation="@anim/path_morph" /></animated-vector>
四、播放动画、创建activity_main.xml布局文件和MainActivity.java
<ImageView android:id="@+id/imageaa" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/avd"/>
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imageView = (ImageView)findViewById(R.id.imageaa); Drawable drawable = imageView.getDrawable(); if (drawable != null && drawable instanceof Animatable){ ((Animatable) drawable).start(); } }
效果图如下:
大功告成 !!!
0 0
- VectorDrawable(三)
- VectorDrawable(一)
- VectorDrawable(二)
- VectorDrawable
- VectorDrawable
- Android动画 SVG VectorDrawable 基础三
- VectorDrawable 怎么玩(Android)
- VectorDrawable问题(待解决)
- Android使用矢量图(SVG, VectorDrawable)实践篇
- Android使用矢量图(SVG, VectorDrawable)实践篇
- VectorDrawable-第一章
- VectorDrawable入门
- VectorDrawable 详解
- VectorDrawable-第一章
- VectorDrawable-第一章
- VectorDrawable(矢量图)
- VectorDrawable 详解
- 矢量图VectorDrawable
- 发现和记录---js常用正则表达式语法总结:Email检查,ip地址验证,手机号码和电话号码验证
- 页面ajax交互,通过地址url先找到服务器,从数据库取值,去掉逗号,再传给页面
- linux解压多个文件
- sencha底部图标平均分配
- redis项目问题
- VectorDrawable(三)
- 对java数组的理解
- CF 363B Fence(和最小的k个数)
- 发现和记录---Java正则表达式的语法与示例
- 解决Linux 下sublime text 同一窗口打开多个标签
- 企业即时通讯软件Cnskype for Business
- Android权限大全
- windows下启动mysql服务的命令行启动和手动启动方法
- LaTex中英文简历代码示例