[英]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.