2015-11-24 84 views

回答

3

您可以使用AnimatorSet

該類扮演了一組指定的順序動畫的對象。 動畫可以設置爲一起播放,按順序播放或在指定延遲後播放。

有兩種不同的方法來添加動畫到 AnimatorSet:要麼playTogether()或playSequentially()方法 可以被稱爲一次全部添加一組動畫,或 播放(動畫)可與Builder 類中的方法一起使用以逐個添加動畫。

可以在它的動畫之間設置一個循環依賴關係爲 的AnimatorSet。例如,可以將動畫a1設置爲 以在動畫a2之前開始,在a3之前開始a2,在a1之前以a3開始。該配置的 結果未定義,但通常會導致 不受任何正在播放的受影響的動畫的影響。由於這個原因(因爲循環依賴關係無論如何都沒有邏輯意義),所以應該避免循環依賴關係,並且動畫的依賴關係流應該只在一個方向上。

您可以查看以下鏈接DEMP情況

  1. Digest Splash for Android
0

什麼是必須要做的是,在圖像上您所提供的所有這些都只是單一的圖像在一定的超時時間之後,它們將從一個轉換到另一個。

您需要爲每個過渡幀添加大量圖像,然後相應地移動它們。

它有點像在Android上創建啓動動畫。 每幅圖像將代表整個動畫的單個幀。

對於動畫圖像,試試這個(基本上是用來過渡的α)

ImageView demoImage = (ImageView) findViewById(R.id.DemoImage); 
int imagesToShow[] = { R.drawable.image1, R.drawable.image2,R.drawable.image3 }; 
animate(demoImage, imagesToShow, 0,false); 



private void animate(final ImageView imageView, final int images[], final int imageIndex, final boolean forever) { 

//imageView <-- The View which displays the images 
//images[] <-- Holds R references to the images to display 
//imageIndex <-- index of the first image to show in images[] 
//forever <-- If equals true then after the last image it starts all over again with the first image resulting in an infinite loop. You have been warned. 

int fadeInDuration = 500; // Configure time values here 
int timeBetween = 3000; 
int fadeOutDuration = 1000; 

imageView.setVisibility(View.INVISIBLE); //Visible or invisible by default - this will apply when the animation ends 
imageView.setImageResource(images[imageIndex]); 

Animation fadeIn = new AlphaAnimation(0, 1); 
fadeIn.setInterpolator(new DecelerateInterpolator()); // add this 
fadeIn.setDuration(fadeInDuration); 

Animation fadeOut = new AlphaAnimation(1, 0); 
fadeOut.setInterpolator(new AccelerateInterpolator()); // and this 
fadeOut.setStartOffset(fadeInDuration + timeBetween); 
fadeOut.setDuration(fadeOutDuration); 

AnimationSet animation = new AnimationSet(false); // change to false 
animation.addAnimation(fadeIn); 
animation.addAnimation(fadeOut); 
animation.setRepeatCount(1); 
imageView.setAnimation(animation); 

animation.setAnimationListener(new AnimationListener() { 
    public void onAnimationEnd(Animation animation) { 
     if (images.length - 1 > imageIndex) { 
      animate(imageView, images, imageIndex + 1,forever); //Calls itself until it gets to the end of the array 
     } 
     else { 
      if (forever == true){ 
      animate(imageView, images, 0,forever); //Calls itself to start the animation all over again in a loop if forever = true 
      } 
     } 
    } 
    public void onAnimationRepeat(Animation animation) { 
     // TODO Auto-generated method stub 
    } 
    public void onAnimationStart(Animation animation) { 
     // TODO Auto-generated method stub 
    } 
}); 

}

對於揭示活性動畫的最後部分,請參閱本SO回答https://stackoverflow.com/a/32199671/4626943

+2

鏈接是*從來沒有[一個好答案](http://stackoverflow.com/help/how-to-answer)。請解釋*爲什麼*您認爲這可能有助於解決所述問題。如果你不確定,那麼這可能不應該是一個答案,而是一個評論。 –

+0

好的,今晚我會做,因爲我目前有點忙。 @MH。 – sayan

+0

@MH。現在看..也許刪除downer? – sayan

相關問題