2015-09-07 114 views
0

我想製作一個具有imageview的應用程序,它將顯示一系列圖像作爲一個像10張圖像的動畫,只用幾英里的時間將它們分開,然後將它們分開希望能夠通過點擊一個按鈕來改變系列,每當我點擊它時,一系列圖像將會改變(可繪製數組)我該怎麼做?imageview中的動畫如何動態更改一系列圖像

我試圖通過使圖像的精靈表,並通過調用run方法(線程)的繪圖方法動畫,但我無法改變精靈做吧..

除了我不能浪費太多時間將圖像轉換爲精靈

+0

什麼是你試過嗎? –

+1

歡迎來到StackOverflow,不幸的是你的問題沒有展示任何先前研究的嘗試。爲了得到良好的答覆,建議您在提出問題之前,應出示您已經試圖用代碼或其他方式解決問題的證據。 –

+0

好吧,感謝抱歉。 –

回答

0

爲什麼不使用標準的AnimationDrawable?

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

UPDATE

如果我明白你的意思,以改變你只需要更新您的onClickListener設置新背景下的ImageView播放的動畫,使用此代碼是什麼。

img.setBackgroundResource(R.drawable.spin_animation); 

// Get the background, which has been compiled to an AnimationDrawable object. 
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); 

// Start the animation (looped playback by default). 
frameAnimation.start(); 
+0

如何在點擊時更改圖片組?像這樣可以只動畫一組,但如果我想要多於一組的組合它是否工作? –

0

我認爲你需要你ViewFlipper而不是ImageView的, 嘗試這樣的。

1.in佈局:

<ViewFlipper 
    android:layout_centerInParent="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:flipInterval="40"  
     android:id="@+id/viewFlipper" 
> 

2.and然後在你的活動:

int gallerySplashrImages[]={/*id of the image you want to display(ex:R.drawable.calque0,R.drawable.calque1,...)*/}; 

    viewFlipper =(ViewFlipper)findViewById(R.id.viewFlipper); 
    viewFlipper.setAutoStart(true); 
    for(int i=0;i<gallerySplashrImages.length;i++) 
     { 
      setFlipperImage(gallerySplashrImages[i]); 
     } 

3.setFlipperImage

private void setFlipperImage(int res) 
    { 
ImageView image = new ImageView(getApplicationContext()); 
image.setBackgroundResource(res); 
viewFlipper.addView(image); 
}