6

I have a simple LinearLayout with two Buttons side by side. They are supposed to slide into and out of view from the right side of the screen when needed. I have the animation working and the rest of the work is done, but I have one last problem to solve.

How can I set the LinearLayout's visibility to View.GONE after the slide out animation is complete? I need it to disappear once it's of screen.

CodeFusionMobile
  • 14,812
  • 25
  • 102
  • 140

3 Answers3

13

Grab a reference of your Animation object doing the animation. Call Animation#setAnimationListener and in the listener's onAnimationEnd method set the visibility to View.GONE.

Rich Schuler
  • 41,814
  • 6
  • 72
  • 59
  • 5
    If `setFillAfter()` is true, this will fail? Since the View state after animation was visible, so it will fail to hide because `setFillAfter()` is saying hold that state. I am doing this, and my view is still visible, somehow I need to have `setFillAfter()` true because of the position. – Talha Nov 15 '16 at 09:17
  • `view.clearAnimation()` before using `setVisibility(View.GONE)` if you need `setFillAfter(true)` – Mohamed Ben Romdhane Mar 11 '22 at 09:51
3

Duplicate : https://stackoverflow.com/a/7606533/3717188

anim.setAnimationListener(new Animation.AnimationListener(){
  @Override
  public void onAnimationStart(Animation arg0) {
  }           
  @Override
  public void onAnimationRepeat(Animation arg0) {
  }           
  @Override
  public void onAnimationEnd(Animation arg0) {
  }
});
Community
  • 1
  • 1
0
LinearLayout al = (LinearLayout) findViewById(R.id.layoutid);  
al.setVisibility(view.INVISIBLE);

Add the above code in your

onAnimationEnd(){
}
Taryn
  • 242,637
  • 56
  • 362
  • 405
Rahulkapil
  • 294
  • 4
  • 13