Reputation: 7585
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.
Upvotes: 0
Views: 598
Reputation: 7127
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!
Upvotes: 1
Reputation: 1007604
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.
Upvotes: 1