views:

38

answers:

2

Hello, i try to animate a TextView on a changeText But always see only one direction of the animation, i only see the fadeout

What i try is: beforChange = fadeOut and onChange or after fadein

here is my code in the onCreate method of my activity:

    final Animation out = new AlphaAnimation(1.0f, 0.0f);
    out.setDuration(1000);

    final Animation in = new AlphaAnimation(0.0f, 1.0f);
    in.setDuration(1000);


    bidFirst.setAnimation(out);
    bidMiddle.setAnimation(out);
    bidLast.setAnimation(out);

    TextWatcher bidWatcher = new TextWatcher() {
      public void onTextChanged(CharSequence s, int start, int before, int count) {
        in.startNow();
        bidFirst.setAnimation(out);
        bidMiddle.setAnimation(out);
        bidLast.setAnimation(out);
      }

      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        out.startNow();
        bidFirst.setAnimation(in);
        bidMiddle.setAnimation(in);
        bidLast.setAnimation(in);
      }

      public void afterTextChanged(Editable s) {
      }
    };
    bidFirst.addTextChangedListener(bidWatcher);
    bidMiddle.addTextChangedListener(bidWatcher);
    bidLast.addTextChangedListener(bidWatcher);

i think there is something wrong in my code but for my believe it has to work.

What i have now is: on every setText the changed Text only FadeOut but after the text has changed and never FadeIn!?

A: 

By the look of your code you are telling the TextView to fade out after a change rather than fade in.

Also I'm not sure how effective this code will be as beforeTextChanged gets called only moments before the text is changed. There simply wont be enough time for any animation to happen on beforeTextChanged as it will be instantly replaced by your code in onTextChanged

Edit** Reply to comment below

So to get the textview to fade out then fade in with new content I would programmatically start a fadeOut animation rather than using a Textwatcher. I would give the fadeOut animation an AnimationListener and on animationEnd you can then set the new text before starting your fadeIn animation.

disretrospect
do you know how to make it more effectiv? I only want a fadeout/fadein whenether a setText is called. I try to use a TextSwitcher but i am not sure if this is usefull for more TextViews.
Mirko
+2  A: 

TextSwitcher is exactly what you are looking for. Just use their setInAnimation() and setOutAnimation. Than the animations will run automatically if you change the text by setText()

WarrenFaith
Sounds good to me
disretrospect