Вопрос

I want to apply an animation to a view and show it when the animation has ended through a AnimationListener. My code works for devices 4.x but it's not working for a 2.3.3 device, the onAnimationStart and onAnimationEnd methods are never called.

 final Animation toTopAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.move_up);
 toTopAnimation.setDuration(250);
 toTopAnimation.setFillBefore(true);
 toTopAnimation.setFillAfter(true);

 toTopAnimation.setAnimationListener(new AnimationListener() {
     @Override
     public void onAnimationStart(Animation animation) {
          Log.i("log", "onAnimationStart");
     }
     @Override
     public void onAnimationEnd(Animation animation) {
         Log.i("log", "onAnimationEnd");
         mQuickReturnView.setVisibility (View.VISIBLE);
     }

     @Override
     public void onAnimationRepeat(Animation animation) {
     }
 });

  mQuickReturnView.setAnimation(toTopAnimation);
  mQuickReturnView.startAnimation(toTopAnimation);

Can you see anything wrong?

Thanks

Это было полезно?

Решение

I had a similar issue and managed to solve it. I'm still not really sure what's the reason behind this problem, but it's lying somewhere around the content of the view and the way gingerbread handles its drawing.

In my case I had a RelativeLayout which had some views in it. The animation would work only if I changed some value of a child view in my RelativeLayout before calling the animation. For example, I had a TextView inside, so I would call the setText() method. Maybe you should try it too:

// ---
mQuickReturnView.setAnimation(toTopAnimation);
someViewInsidemQuickReturnView.setText(getResources().getString(R.string.some_string));
mQuickReturnView.startAnimation(toTopAnimation);
// ---

The setText() method updates the view in some way and the animation works fine after that.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top