2012-05-03 25 views
2

找不到解決方案,在我調用myImageView.clearAnimation()後再次啓動動畫。動畫在onPageSelected中設置,但startoffset超時不起作用。Android:清除後如何重新啓動動畫

或者是否有任何其他方法取消thr動畫來獲取未觸及的imageview,並調用onPageSelected時調用相同的視圖agian相同的動畫。

我tryed調用myImageView.getAnimation()retart()在onPageScrollStateChanged但動畫仍然在查看...

這裏是我的代碼:

public class myActivity extends Activity { 
... 
private ImageView myImageView; 

private static final Integer startOffset = 5000; 
private static final Integer duration= 2500; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    ... 
    currentImageView = (ImageView) findViewById(R.id.dashboardIndicator); 
    currentImageView.setAnimation(indicatorAnimation()); 
    ... 
} 

private Animation indicatorAnimation() { 
    Animation alphaAnimation = new AlphaAnimation(1, 0.2F); 
    alphaAnimation.setInterpolator(new AccelerateInterpolator()); 
    alphaAnimation.setStartOffset(startOffset); 
    alphaAnimation.setDuration(duration); 
    alphaAnimation.setFillAfter(true); 

    return alphaAnimation; 
} 

ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() { 
    @Override 
    public void onPageSelected(int position) { 
     // Need here to start the animation again 
     myImageView.setAnimation(indicatorAnimation()); 
     // Set's the animation but don't starts it after the startOffset timeout 
    } 

    @Override 
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } 

    @Override 
    public void onPageScrollStateChanged(int position) { 
     // Need here to cancel the animation to have no Alpha value on the imageview 
     myImageView.clearAnimation(); 
     // image view 100% visible 
    } 
};} 

回答

0

你不需要清除動畫,直接調用starAnimation

+0

當頁面滾動到頁面滾動時,動畫應該停止,滾動完畢後動畫應該在超時後啓動... –

相關問題