向 AnimationDrawable 添加过渡 [英] Add transition to an AnimationDrawable

查看:27
本文介绍了向 AnimationDrawable 添加过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a set of 10 images, and I want to create an animation where I cross fade between them. I've been looking into built-in Drawable to achieve such a thing, but no luck on that part. There is the AnimationDrawable, that switch between pictures, but it doesn't animate the switch. There is the TransitionDrawable, that cross fade between two pictures, but no more than two.

地狱.

我在 Google 上寻找了一些解决方案,但在这方面没有运气.所以我正在考虑实现我自己的 drawable 来实现这样的事情.有大佬指点一下吗?

I looked for some solution on Google, but no luck on that part. So I'm thinking about implementing my own drawable to achieve such a thing. Would any of you have any pointers ?

提前致谢.

推荐答案

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

Not sure if you found an answer to this, but I had the same problem and ended up building my own class based on 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.

CyclicTransitionDrawable 的代码是 可在 Github 上使用.

The code for the CyclicTransitionDrawable is available on Github.

这篇关于向 AnimationDrawable 添加过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆