TranslateAnimation无法按预期工作

我想使用TranslateAnimation移动一些线性布局。 我有2个问题。 我的基础SDK是Android 2.2。

  1. 即使动画完成,线性布局中的可触摸区域也根本没有移动。
  2. 动画结束后,屏幕闪烁几帧。

起初,我没有使用AnimationListener和LinearLayout.layout()。 当我使用以下代码完成动画时,视图的位置确实发生了变化。 但似乎在动画期间,可触摸区域没有与视图一起移动。 结果,当我试图在动画后点击视图上的任何按钮时,没有任何反应。 如果我单击按钮的原始区域(动画发生前的原始区域),则会触发on_click_listener。

然后我删除了这行代码,

tmpAnimation.setFillAfter(true); 

并尝试了AnimationListenerLinearLayout.layout() 。 它确实帮助并解决了第一个问题。

但是出现了2个问题。 在动画之后,我的一些线性布局会闪烁几帧然后又回到订单状态。

我已经尝试过midLinearlayout.requestLayout() ,它不起作用。我尝试实现了Animation.AnimationListener并覆盖onAnimationEnd,就像有人说的那样,但它也不起作用。

 TranslateAnimation tmpAnimation = new TranslateAnimation(midLinearlayout.getLeft(),midLinearlayout.getLeft(),midLinearlayout.getTop(),midLinearlayout.getTop()+100); //tmpAnimation.setFillAfter(true); tmpAnimation.setDuration(2000); tmpAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void onAnimationEnd(Animation animation) { Log.v("onflingTest","top="+midLinearlayout.getTop()+" left="+midLinearlayout.getLeft()+" right" + midLinearlayout.getRight()); midLinearlayout.layout(midLinearlayout.getLeft(), midLinearlayout.getTop()+100, midLinearlayout.getLeft() + midLinearlayout.getMeasuredWidth(), midLinearlayout.getTop()+ 100 + midLinearlayout.getMeasuredHeight()); } @Override public void onAnimationRepeat(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } }); 

我通过以下代码解决了这个问题:

 linearlayout.clearAnimation(); 

看到链接: EditText在动画后卡住并且在滚动时还活着……?

我在动画完成后发布View.GONE的帮助解决了这个问题

问题是布局B完成动画后,我错过了使视图状态为View.GONE。 添加View.GONE带回了控件。