views:

30

answers:

2

Hey,

I was able to get the animation to work on the emulator -- however my problem is that it animates for a second, but then then goes back to its original posistion right after it finishes animating. How can I stop this for happening.

This is how I animate my objects:

    private void doAnimations() {

  logo.setVisibility(View.INVISIBLE);
  logo.setBackgroundDrawable(null);
  logo.setMaxHeight((logo.getHeight()/2));
  Animation animation = new TranslateAnimation(0, 0, 0, -200);
  usernameEdit.startAnimation(animation);
 }

Any help is appreciated. Thanks.

+1  A: 

How can I stop this for happening.

Register a listener on the animation. Then, when the listener is told that the animation is complete, do something to the actual layout to make your change permanent.

CommonsWare
Hi Mark.Thanks for your help. But in this case, I want to add a listener to the button that I am animating -- however I want it to be click able before and after I animate it. From your response, I see that just registering a new listener won't do it -- what do you mean do something to the acutal layout? I don't have x,y locations set for the button since its in a linear layout with other things, so what could I do to the layout to set the new listener (after the button has been animated).
hwrdprkns
@hwrdprkns: "But in this case, I want to add a listener to the button that I am animating -- however I want it to be click able before and after I animate it." `AnimationListener` and `OnClickListener` are different things. "what do you mean do something to the acutal layout?" Animations are transient. If you want your change to be permanent, you need to modify `LayoutParams` on appropriate widgets. In other words, ignore the animation for the moment, and figure out how you would reposition the widget using changes to your layout. Then, do that work when the animation ends.
CommonsWare
@CommonsWare: "modify LayoutParams" -- I'll try doing that. Thanks for the advice.
hwrdprkns
+1  A: 

Though animation.setFillAfter(true); is a good start but from my experience i have seen that though by this method the visible view does shift to the place where the animation stops but still the control remains where it was earlier...

To illustrate it, let us say u had a Button "btn1" at position A, the animation stops at say position B, now when u set animation.setFillAfter(true);, after the animation stops, the view will be visible at position B but clicking it wont work out. Though if you click at position A (where nothing is visible) btn1's onClickListener method will be called...

Hence as i said earlier, the view gets displayed(at position B) but not the control(which remains at position A)... So its better you go for Mark's(CommonsWare's) method of setting animation listener and making the desired changes when animation stops...

Hope this helps!

JaVadid
Thanks. I understand what you mean -- and if its cleaner code I'll implement it that way.
hwrdprkns