2

I applyed a TranslateAnimation to an EditText with the FillAfter=true in order to keep its position at the end of the animation. The animation works properly but the problem is that I can't enter to the edittext anymore. I think it's due to the fact that the animation affects only the rendering without modifying the actual view coordinates.

Is there any possibility to maintain the final coordinates with the edittext normally working?

Thanks, Daniele

Daniele
  • 21
  • 1
  • 4

1 Answers1

3

Unfotunately the animation only renders the raw pixels of the animated element, but not its "android-intern" position. The best solution (that i am able to come up with) is to use an AnimationListener and set the position of the animated element correctly after the animation has finished. Here is my code to slideDown 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);



}
muetzenflo
  • 5,653
  • 4
  • 41
  • 82