有一个需求是做一个移动的箭头,循环往复向上移动的效果。
一开始想到帧动画,让设计切好图,定好时间就ok了。代码很简单:
image.setImageResource(R.drawable.animal_totop);
AnimationDrawable animationDrawable = (AnimationDrawable) image.getDrawable();
animationDrawable.start();
获取到AnimationDrawable,然后start就可以了。动画是这样写的:
<?xml version="1.0" encoding="utf-8"?><!--
根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
根标签下,通过item标签对动画中的每一个图片进行声明
android:duration 表示展示所用的该图片的时间长度
-->
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/totop1"
android:duration="200"></item>
<item
android:drawable="&#