¿Cómo eliminar una vista animada después de que termine la animación en Android?

Estoy usando una animación en movimiento de derecha a izquierda para un RelativeLayout.

Traté de establecer la visibilidad de 'GONE' para el diseño en el onAnimationEnd() , pero no está funcionando. La vista animada todavía está allí en el lugar donde para.

Este es el código que usé:

Creación de animación de derecha a izquierda:

 TranslateAnimation animate = new TranslateAnimation(0,-rlImages.getWidth()/2,0,0); animate.setDuration(1000); animate.setFillAfter(true); 

Configuración de la animación en el diseño:

 centre_leftanimate.startAnimation(animate); 

Adición de oyentes a la animación:

 animate.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub centre_leftanimate.setVisibility(View.GONE); // I wants to make the visibility of view to gone,but this is not working half_left.setVisibility(View.VISIBLE); } }); 

¿Cómo hacer que la visibilidad de la vista animada sea invisible después del final de la animación?

Por favor recomiende.

Tuve el mismo problema, excepto que en realidad eliminado la vista de ser animado, pero la animación persistió!

La solución simple es realmente cancelar la animación, entonces usted puede ocultar o quitar la vista.

 animatedView.getAnimation().cancel(); 

O si todavía tiene su objeto de animación:

 animation.cancel(); 

EDIT: Parece que algunos sobrantes con la solución anterior, por lo que agregó esto:

 animatedView.setAnimation(null); 

Puede configurar la visibilidad de su vista cuando lo desee. Si lo configura en View.INVISIBLE justo después del inicio de la animación, la animación será visible y la vista desaparecerá tan pronto como se detenga la animación. Creo que el problema con su código podría ser que está utilizando GONE en lugar de INVISIBLE. El segundo problema podría ser que se inicia la animación antes de establecer el oyente, pero con mi solución que no necesita realmente ningún oyente. Además, quitar la opción FillAfter.

  TranslateAnimation animate = new TranslateAnimation(0,-rlImages.getWidth()/2,0,0); animate.setDuration(1000); centre_leftanimate.startAnimation(animate); centre_leftanimate.setVisibility(View.INVISIBLE); 

Tuve el mismo problema y en mi caso la eliminación

 android:fillAfter="true" 

En la animación responsable de quitar la vista y este código resuelve mi problema. Pero otros tendrán mejor código.

 viewToHide.startAnimation(animationForHide); viewToHide.setVisibility(View.GONE); 

Tuve el mismo problema y resolver este problema con la respuesta de esta pregunta Android – eliminar Ver cuando su animación terminó .

EDIT: Usted puede hacer algo como eso:

 final MenuActivity MN= MenuActivity.this; AFade.setAnimationListener(new Animation.AnimationListener(){ @Override public void onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { LayoutMain.post(new Runnable() { public void run () { // it works without the runOnUiThread, but all UI updates must // be done on the UI thread MN.runOnUiThread(new Runnable() { public void run() { LayoutMain.removeView(NextButton); } }); } }); } }); 

LayoutMain es el diseño que contiene la vista. MN es tu actividad.

Sé que esto es una vieja pregunta pero encontré este problema hoy y quise mostrar cómo lo solucioné, porque aunque las respuestas fijadas ya ayudaron, ninguno de ellos trabajaba perfectamente para mi caso.

En mi caso he creado una vista personalizada dinamically, aplicado 2 animaciones (alfa y traducción) y eliminado la vista después de las animaciones se hicieron. Así es como lo hice:

 //Create fade out animation AlphaAnimation fadeOut = new AlphaAnimation(1f, 0f); fadeOut.setDuration(1000); fadeOut.setFillAfter(true); //Create move up animation TranslateAnimation moveUp = new TranslateAnimation(0, 0, 0, -getHeight() / 6); moveUp.setDuration(1000); moveUp.setFillAfter(true); //Merge both animations into an animation set AnimationSet animations = new AnimationSet(false); animations.addAnimation(fadeOut); animations.addAnimation(moveUp); animations.setDuration(1000); animations.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //Hide the view after the animation is done to prevent it to show before it is removed from the parent view view.setVisibility(View.GONE); //Create handler on the current thread (UI thread) Handler h = new Handler(); //Run a runnable after 100ms (after that time it is safe to remove the view) h.postDelayed(new Runnable() { @Override public void run() { removeView(view); } }, 100); } @Override public void onAnimationRepeat(Animation animation) { } }); view.startAnimation(animations); 

Tenga en cuenta que esto se hizo dentro de una vista personalizada (que amplió un FrameLayout), todo se ejecuta en el subproceso de interfaz de usuario.

  • El formato de paquete xml de Android no reconoce las propiedades de aapt
  • Android: cómo utilizar ValueAnimator
  • ¿Cuál es la diferencia entre un animador y una animación?
  • Problema de animación de botones de acción flotante
  • Animación de propiedades de Android: cómo aumentar la altura de la vista?
  • Animador de animación personalizada
  • Diapositiva xml animación en la actividad de cambio en android
  • Cómo invertir la dirección de la marquesina de un TextView
  • Android no anima alfa si es inicialmente cero
  • Android: el salto de Listview a scrollview
  • Cómo reducir una actividad de acabado a un rectángulo
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.