Android动画 SVG VectorDrawable 基础三
2017-07-03 18:38
555 查看
使用动态的VectorDrawable
下面来做一个案例
让箭头左右移动
定义两个 object动画
animator/anim_left.xml<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:repeatMode="reverse" android:repeatCount="infinite" android:propertyName="translateX" android:valueFrom="0" android:valueTo="10" android:valueType="floatType"> </objectAnimator>
animator/anim_right.xml
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:repeatMode="reverse" android:repeatCount="infinite" android:propertyName="translateX" android:valueFrom="10" android:valueTo="0" android:valueType="floatType"> </objectAnimator>
VectorDrawable 文件
drawable/arrow.xml<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <group android:name="left"> <path android:fillColor="#FF000000" android:pathData="M9.01,14L2,14v2h7.01v3L13,15l-3.99,-4v3z"/> </group> <group android:name="right"> <path android:fillColor="#FF000000" android:pathData="M14.99,13v-3L22,10L22,8h-7.01L14.99,5L11,9l3.99,4z"/> </group> </vector>
让 drawable文件与 animator绑定起来
drawable/arrow_anim.xml<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/arrow"> <target android:animation="@animator/anim_left" android:name="left"/> <target android:animation="@animator/anim_right" android:name="right"/> </animated-vector>
使用他们
<ImageView android:onClick="anim" android:layout_width="100dp" android:layout_height="100dp" app:srcCompat="@drawable/arrow_anim"/>
public void anim(View v){ ImageView iv = (ImageView) v; Drawable drawabl 4000 e = iv.getDrawable(); if(drawable instanceof Animatable){ ((Animatable)drawable).start(); } }
相关文章推荐
- Android动画 SVG VectorDrawable 基础四
- Android动画 SVG VectorDrawable 基础五 Path动画
- Android动画 SVG VectorDrawable 基础一
- Android动画 SVG VectorDrawable 基础二
- Android VectorDrawable与SVG 实现炫酷动画
- Android svg VectorDrawable 动画效果
- 【基础学习】Android vector xml 将SVG转换成VectorDrawable 资源
- Android高级动画——Vectordrawable
- Android VectorDrawable与SVG
- Android VectorDrawable -->SVG
- Android 支持SVG VectorDrawable
- Android 矢量图(VectorDrawable)及动画(AnimatedVectorDrawable)
- Android VectorDrawable与SVG
- Android_VectorDrawable矢量图与SVG
- 【Android graphics】(一) Android SVG使用之AnimatedVectorDrawable
- Android5.0+高级动画开发-[初识矢量图SVG与VectorDrawable]
- Android VectorDrawable SVG矢量图 xml格式
- Android VectorDrawable与SVG
- Android VectorDrawable与SVG
- Android矢量图VectorDrawable及动画