peanut
peanut

Reputation: 1570

TranslateAnimation Not Working As Expected

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......?

Upvotes: 3

Views: 3185

Answers (1)

user647826
user647826

Reputation:

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.

Upvotes: 1

Related Questions