繁体   English   中英

如何在 Android 中创建口袋妖怪进化类 animation

[英]How to create a pokemon evolution kind animation in Android

我想在我的应用程序中创建一个基本的“口袋妖怪进化”animation,如下所示: 在此处输入图像描述

我一直在玩这个:

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);


}

但是,这在下面发布的 GIF 中没有按预期工作,我该如何解决这个问题?

编辑:

我已将方法更改为:

 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);
    }
}

但是,工作有点奇怪。

目前您正在一次开始所有转换,它们应该排队

例如,您可以使用一些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

将此代码打包到某个方法中,该方法将采用duration参数和一些回调,通知开始/反向模式结束,然后以更短的持续时间再次调用此方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM