programing

onAnimationEnd에서 Android 애니메이션이 완료되지 않았습니다.

nasanasas 2020. 11. 17. 08:10
반응형

onAnimationEnd에서 Android 애니메이션이 완료되지 않았습니다.


true로 설정되어 onAnimationEnd있지만 이벤트가 발생 하면 Android 애니메이션이 실제로 완료되지 않은 것 같습니다 animation.hasEnded.

내 뷰가 끝에서 배경 드로어 블을 변경하고 ScaleAnimation싶지만 완료되기 전에 몇 밀리 초가 변경되었음을 분명히 알 수 있습니다. 문제는 애니메이션이 실제로 끝날 때까지 짧은 시간 동안 새 배경이 표시 (= is)되어 표시되기 때문에 깜박이는 것입니다.

애니메이션의 실제 끝을 얻거나이 짧은 시간 동안 새 배경의 크기가 조정되는 것을 방지하는 방법이 있습니까?

감사합니다!


// 편집하다 : AnimationListener다음 호출을 받기 위해 사용하고 있습니다 .

    @Override
public void onAnimationEnd(Animation animation)
{
    View view = (MyView) ((ExtendedScaleAnimation) animation).getView();

    view.clearAnimation();
    view.requestLayout();
    view.refreshBackground(); // <-- this is where the background gets changed
}

이 문제와 관련된 실제 버그는 다음과 같습니다. http://code.google.com/p/android-misc-widgets/issues/detail?id=8

이것은 기본적으로 AnimationListener가 Animation에 연결될 때 onAnimationEnd 메소드가 제대로 작동하지 않는다는 것을 나타냅니다.

해결 방법은 애니메이션을 적용한 뷰에서 애니메이션 이벤트를 수신하는 것입니다. 예를 들어 처음에 이와 같이 애니메이션에 애니메이션 리스너를 연결 한 경우

mAnimation.setAnimationListener(new AnimationListener() {
    @Override
    public void onAnimationEnd(Animation arg0) {
        //Functionality here
    }
});

다음과 같이 ImageView에 애니메이션을 적용합니다.

mImageView.startAnimation(mAnimation);

이 문제를 해결하려면 이제 사용자 지정 ImageView를 만들어야합니다.

public class MyImageView extends ImageView {

그런 다음 onAnimationEndView 클래스 메서드 를 재정의하고 모든 기능을 제공합니다.

@Override
protected void onAnimationEnd() {
    super.onAnimationEnd();
    //Functionality here
}

이것은이 문제에 대한 적절한 해결 방법입니다. 애니메이션에 연결된 AnimationListener의 onAnimationEnd 메서드와는 반대로 오버-리든 View-> onAnimationEnd 메서드에 기능을 제공합니다.

이것은 제대로 작동하며 애니메이션이 끝날 때 더 이상 깜박임이 없습니다. 도움이 되었기를 바랍니다.


나는 호출하여이 문제를 해결하려면 아베했다 clearAnimation () 뷰에를 내부에 애니메이션을 onAnimationEnd 깜박임를 나른 것을, 그것의 이상한 이유 onAnimationEnd 콜백은 애니메이션이 이미 종료 된 경우에만 호출되어 있어야합니다 같은 사람이, 그렇게 할 것입니다. 하지만 대답은보기 / 레이아웃이 애니메이션 콜백을 처리하는 방법에 대한 프레임 워크의 깊이에 있다고 생각합니다. 지금은 해킹없는 솔루션으로 생각하면됩니다.

        animation.setAnimationListener(new AnimationListener() {

        public void onAnimationEnd(Animation anim) {
            innerView.clearAnimation();   // to get rid of flicker at end of animation

            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams
            (innerBlockContainer.getWidth(), innerBlockContainer.getHeight());

            /* Update lp margin, left/top to update layout after end of Translation */
            ViewGroup parent_ofInnerView = (ViewGroup)innerView.getParent();
            vp.updateViewLayout(innerBlockContainer, lp);

        }

        public void onAnimationRepeat(Animation arg0) {}

        public void onAnimationStart(Animation arg0) {
        }

    });

     innerView.startAnimation(animation);

비슷한 문제가 있었고 사용자 정의 뷰 클래스와 함께 Soham의 솔루션을 사용했습니다.

잘 작동했지만 결국 저에게 효과가있는 더 간단한 솔루션을 찾았습니다.

를 호출 한 후 view.StartAnimation(animation)내 프로그램의 다음 단계 전에 애니메이션이 완료 될 수있을만큼 길지만 사용자가 눈에 띄지 않을만큼 짧은 지연 시간을 추가했습니다.

new Handler().postDelayed(new Runnable() {
       @Override
       public void run() {
           nextStepInMyProgram();
       }
     }, 200);// delay in milliseconds (200)

나는 같은 문제가 있었고 그것을 사용하여 해결했습니다.

view.clearAnimation();

전에

view.startAnimation(anim);

어떤 이유로 onAnimationStart는 제대로 작동하지만 onAnimationEnd는 작동하지 않습니다. 그래서 여기에 내가 원래 어떻게했고 내가 변경 한 것 :

시도 1 (깜박임) : a) 이미지를 0px에서 80px로 이동 b) onAnimationEnd에서 이미지의 위치를 ​​80px로 설정합니다.

시도 2 (깜박임 없음) : a) onAnimationStart에서 이미지의 위치를 ​​80px로 설정합니다. b) 이미지를 -80px에서 0px로 이동합니다.

이해가 되길 바랍니다. 기본적으로 내가했던 방식을 뒤집어


Try to use getAnimation() from your object:

public void onShowListBtnClick(View view)
    {
        rightPanel.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_left));

        rightPanel.getAnimation().setAnimationListener(new Animation.AnimationListener() {    
            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // write your code here
            }
        });
}

annimation can be also stopped on screen rotation. in this case onAnimationEnd() is not being called. my workaround:

 animation.setDuration(animationDuration);
 animation.setAnimationListener(new AnimationListenerAdapter() {...});
 view.startAnimation(animation);
 handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if(!animation.hasEnded()) {
                    // here you can handle this case
                }
            }
        }, animationDuration + 100);

An easy fix is to add one line to AnimationListener.onAnimationEnd():

@Override 
public void onAnimationEnd(Animation a) {
    a.setAnimationListener(null);
}

I had this issue because my Animation was not started in the main thread. This resulted in a duration of 0. However , the Animation did play correctly - it just called onAnimationEnd() immediately after execution.


If you are using repeat count as infinite, then onAnimationEnd would not get called. Check the documentation link


This worked for me:

@Override
public void onAnimationUpdate(ValueAnimator animation) {
    if (Float.compare(animation.getAnimatedFraction(),1.0f)) {
    // animation ended;
        //do stuff post animation
    }
}

참고URL : https://stackoverflow.com/questions/4750939/android-animation-is-not-finished-in-onanimationend

반응형