2015-10-15 173 views
16

我有對稱的圖像,我想順利地從右到左無限地移動它。我試圖使用TranslateAnimation,但首先我必須正確設置我的圖像,這很困難,主要是因爲此圖像使用所有的屏幕寬度,我應該設置負邊距。還有其他解決方案嗎?是否有移動圖像而不移動ImageView的可能性?平滑的幻燈片圖像單向

+0

您可以使用尋呼機也爲這一點。這裏是演示http://codetheory.in/android-image-slideshow-using-viewpager-pageradapter/ –

+0

是的,'正確'的方法是使用ViewPager來刷圖像。 – Muz

回答

13

最後,我通過我自己做它和解決方案將2個圖像放在一起,然後測量屏幕寬度並使用2個TranslateAnimation,一個從屏幕寬度到0,另一個從0到屏幕寬度:

TranslateAnimation anim = new TranslateAnimation(0, -screenWidth, 0, 0); 
    TranslateAnimation anim2 = new TranslateAnimation(screenWidth, 0, 0, 0); 
    anim.setDuration(5000); 
    anim.setRepeatCount(Animation.INFINITE); 
    anim.setInterpolator(new LinearInterpolator()); 
    anim2.setDuration(5000); 
    anim2.setRepeatCount(Animation.INFINITE); 
    anim2.setInterpolator(new LinearInterpolator()); 
    backgroundOverlayImage.startAnimation(anim); 
    backgroundOverlayImage2.startAnimation(anim2); 
2

我想這是你正在嘗試做的:

 TranslateAnimation anim = new TranslateAnimation(0, -1000, 0, 0); 
     anim.setDuration(1500); 
     anim.setFillAfter(true); 
     anim.setRepeatCount(0); 
     anim.setInterpolator(this, Android.Resource.Animation.LinearInterpolator); 

編輯: 在最後不要忘了imageView.startAnimation(anim);

+1

這個解決方案几乎沒有問題,它可以顯示圖像移動太多時的空白區域,我必須設置負邊距才能使其工作。 – falsetto

0

雖然你得到了答案,try這個存儲庫,這將解決所有關於幻燈片的查詢,並且還會爲您的視圖添加自定義動畫!

Preview