[英]How to create a pokemon evolution kind animation in Android
I want to create a basic "pokemon evolution" animation in my app, something like this:我想在我的应用程序中创建一个基本的“口袋妖怪进化”animation,如下所示:
I've been playing with this:我一直在玩这个:
private void evolveAnimation(Pokemon selectedToEvolvePokemon) {
Drawable backgrounds[] = new Drawable[2];
Resources res = getResources();
backgrounds[0] = res.getDrawable(selectedPokemon.getImage(getContext()));
backgrounds[1] = res.getDrawable(selectedToEvolvePokemon.getImage(getContext()));
TransitionDrawable crossfader = new TransitionDrawable(backgrounds);
evolveTransition.setImageDrawable(crossfader);
crossfader.setCrossFadeEnabled(true);
crossfader.startTransition(3000); //The animation starts slow
crossfader.reverseTransition(3000);
crossfader.startTransition(2000);//It gets faster slow
crossfader.reverseTransition(2000);
crossfader.startTransition(1000); //And faster
crossfader.reverseTransition(1000);
}
However, this is not working as expected in the GIF posted below, how can I fix this?但是,这在下面发布的 GIF 中没有按预期工作,我该如何解决这个问题?
EDIT:编辑:
I've changed the method to this:我已将方法更改为:
private void doEvolve(TransitionDrawable crossfader, int durationMills) {
crossfader.startTransition(durationMills);
Handler h = new Handler(Looper.getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
crossfader.reverseTransition(durationMills);
}
}, durationMills);
if (durationMills != 0) {
doEvolve(crossfader, durationMills - 100);
} else {
crossfader.startTransition(0);
}
}
However, works a bit strange.但是,工作有点奇怪。
currently you are starting all transitions at once, they should be queued目前您正在一次开始所有转换,它们应该排队
for example you may use some Handler
and its postDelayed
method, eg例如,您可以使用一些
Handler
及其postDelayed
方法,例如
crossfader.startTransition(3000);
Handler h = new Handler(Looper.getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
crossfader.reverseTransition(3000);
}
}, 3000); // will start after startTransition duration
pack this code into some method which will take duration
param and some callback informing that start/reverse pattern ended, then call this method again with shorter duration将此代码打包到某个方法中,该方法将采用
duration
参数和一些回调,通知开始/反向模式结束,然后以更短的持续时间再次调用此方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.