简体   繁体   English

AnimationListener无法在蜂窝设备上运行

[英]animationlistener not working pre honeycomb devices

I want to apply an animation to a view and show it when the animation has ended through a AnimationListener. 我想将动画应用于视图,并在动画通过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. 我的代码适用于设备4.x,但不适用于2.3.3设备,永远不会调用onAnimationStart和onAnimationEnd方法。

 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. 就我而言,我有一个RelativeLayout ,其中有一些视图。 The animation would work only if I changed some value of a child view in my RelativeLayout before calling the animation. 仅当在调用动画之前我在RelativeLayout中更改了子视图的某些值时,动画才起作用。 For example, I had a TextView inside, so I would call the setText() method. 例如,我内部有一个TextView ,所以我将调用setText()方法。 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. setText()方法以某种方式更新视图,然后动画可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM