Android LayoutImationController:如何强制第一个孩子等待最后一个孩子';重复之前要完成的动画是什么?
我正在尝试创建一个动画,其中包含以下图像: 变成此图像: 三个条逐渐消失,就像1…2…3。。。然后回到零。此时动画将重复。以下是我试图使其发挥作用的内容:Android LayoutImationController:如何强制第一个孩子等待最后一个孩子';重复之前要完成的动画是什么?,android,android-animation,Android,Android Animation,我正在尝试创建一个动画,其中包含以下图像: 变成此图像: 三个条逐渐消失,就像1…2…3。。。然后回到零。此时动画将重复。以下是我试图使其发挥作用的内容: AlphaAnimation anim = (AlphaAnimation) AnimationUtils.loadAnimation(this, R.anim.fade_in); anim.setRepeatMode(Animation.RESTART); anim.setRepeatCount(Animatio
AlphaAnimation anim = (AlphaAnimation) AnimationUtils.loadAnimation(this, R.anim.fade_in);
anim.setRepeatMode(Animation.RESTART);
anim.setRepeatCount(Animation.INFINITE);
anim.setStartOffset(3000);
LayoutAnimationController controller = new LayoutAnimationController(anim, 0.5f);
rl.setLayoutAnimation(controller);
rl.startLayoutAnimation();
这几乎是可行的,但问题是这些wifi条的视图组中的第一个孩子不会等到最后一个孩子完成动画后才关机。结果是一个节拍看起来像1…2…3…1…2.3…1…3…1…2.3,而不是一个漂亮的1…2…3…1…2…3。我需要找到一种方法,使控制器等待,直到循环完成,然后再设置第一个子关闭。我还没有找到任何解决方案,有人有意见吗?我愿意完全改变我做这件事的方式,在这之前,这个LayoutImationController类似乎是最好的方式
谢谢 当我必须为图像使用动画时,我准备了帧。我在这个类中使用了AnimatioDrawable:
* This class is a hack to simply get an on finish callback for an
* AnimationDrawable.
*
*/
public class CustomAnimationDrawable extends AnimationDrawable {
// We need to keep our own frame count because mCurFrame in AnimationDrawable is private
private int mCurFrameHack = -1;
// This is the Runnable that we will call when the animation finishes
private Runnable mCallback = null;
/*
* We override the run method in order to increment the frame count the same
* way the AnimationDrawable class does. Also, when we are on the last frame we
* schedule our callback to be called after the duration of the last frame.
*/
@Override
public void run() {
super.run();
mCurFrameHack += 1;
if (mCurFrameHack == (getNumberOfFrames() - 1) && mCallback != null) {
scheduleSelf(mCallback, SystemClock.uptimeMillis() + getDuration(mCurFrameHack));
}
}
/*
* We override this method simply to reset the frame count just as is done in
* AnimationDrawable.
*/
@Override
public void unscheduleSelf(Runnable what) {
// TODO Auto-generated method stub
super.unscheduleSelf(what);
mCurFrameHack = -1;
}
public void setOnFinishCallback(Runnable callback) {
mCallback = callback;
}
public Runnable getOnFinishCallback() {
return mCallback;
}
}
在我的代码中,我像这样使用它:
CustomAnimationDrawable staticAnimation = new CustomAnimationDrawable();
//add frames with resources and duration. step is just a class of mine
staticAnimation.addFrame(getResources().getDrawable(step.getStepImageResId()), step.getStepDuration());
staticAnimation.addFrame(getResources().getDrawable(step.getStepImageResId()), step.getStepDuration());
staticAnimation.addFrame(getResources().getDrawable(step.getStepImageResId()), step.getStepDuration());
staticAnimation.setOneShot(false);
imgView.setBackgroundDrawable(staticAnimation);
staticAnimation.start();
也许不是最好的解决方案,但它满足了我的需要