Reputation: 3429
I have this 2 text views.
http://cl.ly/image/2S0o2O1x470r
signup and login. behind them there's a View with grey background. I want to run an animation that when you press that buttons the grey view moves to the button along with the view pager content.
when I do an xml translate like that :
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
the animation is going right but when it finishes it comes back to place.
how do I keep it in place?
never did absolute animations before and couldn't find anything useful about that issue.
ty
Upvotes: 0
Views: 6214
Reputation: 3429
I solved it, and i'll post my solution in case anyone else get this problem.
I did it in code and not xml, code:
private void rightAnimation() {
//measures the layout width so the button knows how much to move.
int xOffset = signUpLoginLayout.getMeasuredWidth() / 2;
//the animation - xOffset / 2 is how much I want to move right on the Xline.
TranslateAnimation moveAnim = new TranslateAnimation(0, xOffset, 0, 0);
moveAnim.setDuration(500);
moveAnim.setFillAfter(true);
leftSignUpAnimation.startAnimation(moveAnim);
moveAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
//that's to move the viewpager to the desired location.
pager.setCurrentItem(0, true);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
did the same method to move left just switched the animation from (0, xOffset, 0, 0) to (xOffset, 0, 0, 0)
hope this helps someone.
good luck :)
Upvotes: 8