本文介绍了TranslateAnimation工作不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wanted to move some linear layout using TranslateAnimation. I have 2 problems. My base SDK is Android 2.2.

  1. 即使当动画完成后,可触摸区域中的线性布局未动的。
  2. 在屏幕上闪现的一对夫妇帧的动画结束之后。

起初,我没有使用AnimationListener和LinearLayout.layout()。当我用下面的code fnished动画,视图的位置确实变了。但似乎可触摸面积不动了动画中的观点。其结果是,当我试图点击任何按钮上的动画后认为,什么都没有发生。如果我点击了按钮的原始区域(原区前的动画发生),则on_click_listener被triggerred。

At first, I didn't use AnimationListener and LinearLayout.layout(). When I fnished the animation using the following code, the position of the view was indeed changed. But it seemed that the touchable area was not moved with the view during animation. As a result, when I tried to clicked any of the buttons on the view after animation, nothing happened. If I clicked the original area of the buttons (the original area before the animation took place), the on_click_listener was triggerred.

然后我删除了此行的code,

Then i deleted this line of code,

tmpAnimation.setFillAfter(true);

和尝试的 AnimationListener LinearLayout.layout()。它确实帮助和sovled第一问题。

and tried AnimationListener and LinearLayout.layout(). It did help and sovled the 1st problem.

但出现了2个问题。动画结束后,我的一些线性布局会闪烁几帧,然后再订购。

But there came the 2 problem. After the animation, some of my linear layouts would flash for a couple of frames and then back to order.

我已经试过 midLinearlayout.requestLayout(),它不干活试图实现Animation.AnimationListener并覆盖onAnimationEnd就像有人说的,但它也不行。

I've tried midLinearlayout.requestLayout(), it doesn't work.I tried implemented Animation.AnimationListener and override onAnimationEnd like someone said,but it doesn't work either.

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


我已经由code以下解决这个问题:


I've solve this by the code below:

linearlayout.clearAnimation();

见链接:EditText动画和活着回来滚动后stucks ......?

see the link:EditText stucks after animation and alive back on scrolling......?

推荐答案

我解决了这个问题,从职位View.GONE在动画完成

I solved the issue with the help from post View.GONE in animation complete

现在的问题是布局乙完成的动画后,我错过了使视图状态View.GONE。添加View.GONE带回了控制。

The problem is after layout B completes the animation, i missed to make the view state as View.GONE. Adding View.GONE brought back the controls.

这篇关于TranslateAnimation工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 06:36