其他分享
首页 > 其他分享> > android-活动过渡对于动画而言发生得太快

android-活动过渡对于动画而言发生得太快

作者:互联网

编辑

问题可以在这里看到:

enter image description here

我有一个登录屏幕和一个注册屏幕.

当用户单击注册按钮时-我想从登录屏幕滑动到注册屏幕.我的工作还好.

当用户按下注册屏幕上的“后退”按钮时,我想滑回到登录屏幕.

这似乎可以正常工作,但是在动画完成之前,登录屏幕活动正在载入旧活动.

LoginActivity.java

public void createAccount(View view) {
    Log.d(TAG, "Create Account clicked");
    Intent intent = new Intent(getApplicationContext(), SignupActivity.class);
    startActivityForResult(intent, REQUEST_SIGNUP);
    overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
}

RegisterActivity.java

@Override
public void onBackPressed() {
    super.onBackPressed();
    Log.d(TAG, "Back clicked - return to login");
    finish();
    overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}

push_left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromXDelta="100%p"
        android:toXDelta="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
</set>

push_left_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromXDelta="0"
        android:toXDelta="-100%p"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
</set>

push_right_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromXDelta="0"
        android:toXDelta="100%p"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator" />
</set>

push_right_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromXDelta="-100%p"
        android:toXDelta="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator" />
</set>

注意

我已经尝试了以下两种解决方案,但都无法使用.

overridePendingTransition shows second activity too quickly

解决方法:

push_right_in.xml和push_right_out.xml似乎混淆了.

push_right_in.xml应该在屏幕外开始:android:fromXDelta =“-100%p”并在屏幕上结束:android:toXDelta =“ 0”

push_right_out.xml应该在屏幕上开始:android:fromXDelta =“ 0”,然后在屏幕外结束:android:toXDelta =“ 100%p”.

标签:android-xml,android-animation,android,overridependingtransition
来源: https://codeday.me/bug/20191110/2013403.html