0

我想在android中播放一个具有多个视图的动画。这是代码的简化示例。此代码工作不正确。每个 startAnimation() 调用都会影响所有以前的动画视图

请告诉我,为什么它不起作用以及如何正确制作它。

公共 SomeClass() {

private int currentViewID = 0; 
private View[] views = { view1, view2, view3, view4, view5 }
private Animation anim = AnimationUtils.loadAnimation(this.getContext(), android.R.anim.fade_out);

public SomeClass() {
    this.anim.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            if (SomeClass.this.currentViewID != SomeClass.this.views.length) SomeClass.this.hideNextView();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {

        }

    });
    this.hideNextView();
}

private void hideNextView() {
    this.views[this.currentViewID++].startAnimation(this.anim);
}

}

4

1 回答 1

0

如果您不想在课堂上处理许多动画(每个视图一个),您可以在本地执行操作:

private int currentViewID = 0; 
private View[] views = { view1, view2, view3, view4, view5 }

public SomeClass() {
    this.hideNextView();
}

private void hideNextView() {
    final Animation anim = AnimationUtils.loadAnimation(this.getContext(), android.R.anim.fade_out);

    anim.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            if (SomeClass.this.currentViewID != SomeClass.this.views.length) SomeClass.this.hideNextView();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {}

        @Override
        public void onAnimationStart(Animation animation) {}

    });

    this.views[this.currentViewID++].startAnimation(anim);
}
于 2012-08-25T21:54:40.847 回答