2010-12-09 2 views
2

J'ai appliqué une TranslateAnimation à un EditText avec FillAfter = true afin de conserver sa position à la fin de l'animation. L'animation fonctionne correctement mais le problème est que je ne peux plus entrer dans l'edittext. Je pense que c'est dû au fait que l'animation n'affecte que le rendu sans modifier les coordonnées réelles de la vue.Comment puis-je appliquer les modifications à la position d'une vue après une animation?

Y a-t-il une possibilité de maintenir normalement les coordonnées finales avec l'edittext?

Merci, Daniele

Répondre

3

Unfotunately l'animation ne fait que rendre les pixels bruts de l'élément animé, mais pas sa position "android-stagiaire". La meilleure solution (que je suis capable de trouver) est d'utiliser un AnimationListener et de définir correctement la position de l'élément animé une fois l'animation terminée. Voici mon code pour glisserDown a searchWrapper:

public void toggleSearchWrapper() { 

    AnimationSet set = new AnimationSet(true); 

    // slideDown Animation 
    Animation animation = new TranslateAnimation(
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, 
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f 
    ); 



    animation.setDuration(300); 
    animation.setFillEnabled(false); 


    animation.setAnimationListener(new AnimationListener() { 

     @Override 
     public void onAnimationStart(final Animation anim) { 
     }; 

     @Override 
     public void onAnimationRepeat(final Animation anim) { 
     }; 

     @Override 
     public void onAnimationEnd(final Animation anim) { 


      // clear animation to prevent flicker 
      searchWrapper.clearAnimation(); 

      // set new "real" position of wrapper 
      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
      lp.addRule(RelativeLayout.BELOW, R.id.branchFinderIncludeHeader); 
      searchWrapper.setLayoutParams(lp); 

     } 

    }); 


    set.addAnimation(animation); 

    // set and start animation 
    searchWrapper.startAnimation(animation); 



} 
Questions connexes