好吧。很長一段時間過去了,你可能已經解決了這個問題,但是你得到了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);
有了這個代碼你必須通過1..N圖像的容易循環,每一個保持5秒(5000毫秒)與淡入動畫。現在,我做的是設置我的根的背景RelativeLayout的
mLayoutRoot.setBackground(mBackgroundAnimation);
mLayoutRoot.post(new AnimationStarterThread());
而且AnimationStarterThread類
private class AnimationStarterThread implements Runnable {
public void run() {
if(mBackgroundAnimation != null)
mBackgroundAnimation.start();
}
}
嗯,我甚至不記得我做過什麼:-)但你的解決方案看起來非常乾淨,所以讓我們將其標記爲答案! – Redwarp 2012-07-23 12:41:06
有沒有辦法讓它只有一個循環? – Andy 2012-09-20 21:09:51
目前無法限制循環次數。雖然可以添加,但我認爲(從內存中)可以使用原始的TransitionDrawable類來實現。 – 2012-09-23 14:08:52