2

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

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

我尝试在 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
    }
};}
4

1 回答 1

0

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

于 2012-05-03T12:51:17.497 回答