Android:清除后如何重新启动动画

时间:2012-05-03 12:39:31

标签: android android-animation android-viewpager

在调用myImageView.clearAnimation()之后找不到再次启动动画的解决方案。动画在onPageSelected中设置,但是startoffset超时不起作用。

或者是否有任何其他方法可以取消thr动画以获得未触动的imageview以及何时获取 调用onPageSelected为同一视图agian启动相同的动画。

我尝试在onPageScrollStateChanged中调用myImageView.getAnimation()。retart(),但动画仍在视图中...

这是我的代码:

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
    }
};}

1 个答案:

答案 0 :(得分:0)

你不需要清除动画,直接调用starAnimation