×
您的位置: 首页 > 编程笔记

TranslateAnimation工作不正常(TranslateAnimation Not Working As Expected)

Android 时间:2020-06-15  查看:642   收藏

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

  1. Even when the animation is finished, the touchable area in the linear layout was not moved at all.

  2. The screen flashed for a couple of frames right after the animation was finished.

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.

Then i deleted this line of code,

tmpAnimation.setFillAfter(true);

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

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.

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

I've solve this by the code below:

linearlayout.clearAnimation();

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

解决方案

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

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一些线性布局。我有2个问题。我的基地SDK的是Android 2.2。

  1. 即使当动画完成后,可触摸区域中的线性布局未动的。

  2. 在屏幕上闪现的一对夫妇帧的动画结束之后。

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

然后我删除了此行的code,

  tmpAnimation.setFillAfter(真正的);

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

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

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

  TranslateAnimation tmpAnimation =新TranslateAnimation(midLinearlayout.getLeft(),midLinearlayout.getLeft(),midLinearlayout.getTop(),midLinearlayout.getTop()+100);

//tmpAnimation.setFillAfter(true);

tmpAnimation.setDuration(2000);
tmpAnimation.setAnimationListener(新Animation.AnimationListener(){
                    @覆盖
                    公共无效onAnimationStart(动画动画){
                        //要改变的实现方法正文中使用文件|设置|文件模板。
                    }

                    @覆盖
                    公共无效onAnimationEnd(动画动画){
                        Log.v(onflingTest,顶=+ midLinearlayout.getTop()+左=+ midLinearlayout.getLeft()+右+ midLinearlayout.getRight());
                        midLinearlayout.layout(midLinearlayout.getLeft(),midLinearlayout.getTop()+ 100,midLinearlayout.getLeft()+ midLinearlayout.getMeasuredWidth(),midLinearlayout.getTop()+ 100 + midLinearlayout.getMeasuredHeight());
                    }

                    @覆盖
                    公共无效onAnimationRepeat(动画动画){
                        //要改变的实现方法正文中使用文件|设置|文件模板。
                    }
                });

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

  linearlayout.clearAnimation();

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

解决方案

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

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

 

0% (0)
0% (0)