TranslateAnimation does not work as expected

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

  • Even when the animation is finished, the touchable area in the linear layout does not move at all.
  • The screen flashed for several frames immediately after the end of the animation.

At first I did not use AnimationListener and LinearLayout.layout (). When I finished the animation using the following code, the position of the view really changed. But it seemed that the tangible area was not moved with the view during the animation. As a result, when I tried to click any of the buttons on the view after the animation, nothing happened. If I clicked on the source area of ​​the buttons (the source area before the animation), on_click_listener was activated.

Then I deleted this line of code,

tmpAnimation.setFillAfter(true); 

and tried AnimationListener and LinearLayout.layout () . This helped and got around the 1st problem.

But there was 2 problem. After the animation, some of my line layouts will blink for a few frames and then return to order.

I tried midLinearlayout.requestLayout () , it does not work. I tried to implement Animation.AnimationListener and override onAnimationEnd as 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 solved this with the following code:

 linearlayout.clearAnimation(); 

see link: EditText stucks after animation and live back to scroll ......?

+3
source share
1 answer

I solved the problem using View.GONE message in full animation

The problem is that after Layout B completes the animation, I skipped the view state to be View.GONE. Adding View.GONE returns the controls.

+1
source

Source: https://habr.com/ru/post/1500098/


All Articles