android翻译动画绝对 - 从右到左,从左到右

Joz*_*eRi 1 android android-animation

我有这2个文本视图.

http://cl.ly/image/2S0o2O1x470r

注册和登录.在他们身后有一个灰色背景的视图.我想运行一个动画,当你按下那个按钮时,灰色视图会随着视图寻呼机内容一起移动到按钮.

当我做一个像这样的xml翻译时:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
Run Code Online (Sandbox Code Playgroud)

动画是正确的,但当它完成后,它会回到原位.

我该如何保持原位?

从来没有做过绝对的动画,也找不到任何有用的问题.

TY

Joz*_*eRi 7

我解决了它,我会发布我的解决方案,万一其他人得到这个问题.

我在代码而不是xml,代码:

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) {

        }
    });
Run Code Online (Sandbox Code Playgroud)

做同样的方法左移只是将动画从(0,xOffset,0,0)切换到(xOffset,0,0,0)

希望这有助于某人.

祝好运 :)