我有一个基本的动画,可以使图片增长和淡化,语法如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="4.0"
android:fromYScale="1.0"
android:toYScale="4.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:duration="2500"
android:repeatCount="infinite"
android:repeatMode="restart" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2500"
android:repeatCount="infinite"
android:repeatMode="restart"/>
</set>
然后我就这样称呼它
ImageView circleImage = (ImageView) findViewById(R.id.image_loader);
Animation pulseAnimation = AnimationUtils.loadAnimation(this, R.anim.pulse_animation);
circleImage.startAnimation(pulseAnimation);
一切都按预期工作但我想在结束前重复该动画。假设我想每秒重复一次动画,即使它需要2.5秒才能播放。
这样做的正确方法是什么?
答案 0 :(得分:0)
将动画文件名创建为progress_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/animation_one"
android:duration="350"/>
<item
android:drawable="@drawable/animation_two"
android:duration="350"/>
<item
android:drawable="@drawable/animation_three"
android:duration="350"/>
<item
android:drawable="@drawable/animation_four"
android:duration="350"/>
</animation-list>
这里的可绘制文件是应用动画后同一图像的不同图像。
将此动画应用到ImageView中,如下所示:
ImageView ivProgress = (ImageView) this.findViewById(R.id.iv_progress);
// Set the background of the image - In this case an animation
// (/res/anim folder)
ivProgress.setBackgroundResource(R.anim.progress_animation);
// Get the image background and attach the AnimationDrawable to it.
progressAnimation = (AnimationDrawable) ivProgress.getBackground();
progressAniation.start();