大佬教程收集整理的这篇文章主要介绍了Android LayoutAnimationController:如何强制第一个孩子在重复之前等待最后一个孩子的动画完成?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
成为这个图像:
那三根酒吧像1 … 2 …… 3一样淡出…然后回到没有.此时动画将重复.这是我试图做的工作:
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.我需要找到一种方法让控制器等到循环完成后再将第一个孩子关闭.我还没有找到任何解决方案,有没有人有一些意见?我愿意改变我这样做的方式,这个LayoutAnimationController类似乎是迄今为止最好的方法.
谢谢!
* 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.setOneshot(false); imgView.setBACkgroundDrawable(staticAnimation); staticAnimation.start();
可能不是最好的解决方案,但它符合我的需求.
以上是大佬教程为你收集整理的Android LayoutAnimationController:如何强制第一个孩子在重复之前等待最后一个孩子的动画完成?全部内容,希望文章能够帮你解决Android LayoutAnimationController:如何强制第一个孩子在重复之前等待最后一个孩子的动画完成?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。