2013-06-25 59 views
0

我想将动画应用于视图并在动画通过AnimationListener结束时显示它。我的代码适用于设备4.x,但它不适用于2.3.3设备,onAnimationStart和onAnimationEnd方法从不会被调用。animationlistener不工作预蜂窝设备

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); 

你能看到什么不对吗?

谢谢

+0

该代码片段看起来不错,它也必须在pre honycomb设备上工作。伊莫问题在其他地方发布 – Blackbelt

回答

0

我有一个类似的问题,并设法解决它。我仍然不确定这个问题背后的原因是什么,但是它是围绕着视图的内容和姜饼处理绘图的方式。

在我的情况下,我有一个RelativeLayout其中有一些意见。只有在调用动画之前在RelativeLayout中更改了某个子视图的某个值时,该动画才有效。例如,我内部有一个TextView,所以我打电话给setText()方法。也许你应该尝试一下也:

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

setText()方法更新以某种方式视图和动画后工作正常。

+1

谢谢,setText()没有为我工作,但问题是类似的。在我的情况下,我通过隐藏布局中的一些内容来解决它。 – nirvik