添加到AnimationDrawable的转换

Red*_*arp 11 animation android drawable

我有一组10个图像,我想创建一个动画,我在它们之间交叉淡入淡出.我一直在研究内置的Drawable来实现这样的功能,但是那部分没有运气.有一些AnimationDrawable可以在图片之间切换,但它不会为交换机设置动画.有一个TransitionDrawable,它在两张图片之间交叉淡入淡出,但不超过两张.

地狱.

我在Google上寻找了一些解决方案,但在那方面没有运气.所以我正在考虑实现我自己的drawable来实现这样的事情.你们有没有人有任何指示?

提前致谢.

Chr*_*unt 21

不确定你是否找到了答案,但我遇到了同样的问题,最终建立了自己的基于TransitionDrawable的类.

用法:

CyclicTransitionDrawable ctd = new CyclicTransitionDrawable(new Drawable[] { 
  drawable1, 
  drawable2, 
  drawable3, 
  ... 
});

imageView.setImageDrawable(ctd);

ctd.startTransition(1000, 3000) // 1 second transition, 3 second pause between transitions.
Run Code Online (Sandbox Code Playgroud)

Github提供了CyclicTransitionDrawable的代码.


vog*_*Dev 11

好.很长一段时间过去了,你可能已经解决了这个问题,但你得到了AnimationDrawable的setEnterFaceDuration().例:

mBackgroundAnimation = new AnimationDrawable();
mBackgroundAnimation.addFrame(getResources().getDrawable(R.drawable.background1), 5000); 
// ... rest of the frames
mBackgroundAnimation.addFrame(getResources().getDrawable(R.drawable.background6), 5000);
mBackgroundAnimation.setEnterFadeDuration(1000);
mBackgroundAnimation.setOneShot(false);
Run Code Online (Sandbox Code Playgroud)

使用此代码,您可以通过1..N图像轻松循环,每个图像保持5s(5000ms),并带有淡入动画.现在,我所做的是设置我的根RelativeLayout的背景

mLayoutRoot.setBackground(mBackgroundAnimation);
mLayoutRoot.post(new AnimationStarterThread());
Run Code Online (Sandbox Code Playgroud)

还有AnimationStarterThread类

private class AnimationStarterThread implements Runnable {
    public void run() {
        if(mBackgroundAnimation != null)
             mBackgroundAnimation.start();
    }
}
Run Code Online (Sandbox Code Playgroud)