片段之间的动画过渡崩溃

时间:2016-02-17 12:12:42

标签: android fragmenttransaction objectanimator

我试图通过将电流向左淡化并从右侧淡化新电流来动画两个片段之间的过渡。应用程序在运行时崩溃。

minSdkVersion: 16
targetSdkVersion: 23
模拟器在api版本23上运行

活动代码

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.animator.enter_from_right, R.animator.exit_to_left);
    transaction.replace(R.id.listFragmentContainer, fragment);
    transaction.commit();

RES /动画/ enter_from_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
<ObjectAnimator
    android:fromXDelta="100%" android:toXDelta="0%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="700"/>
</set>

RES /动画/ exit_to_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
<ObjectAnimator
    android:fromXDelta="0%" android:toXDelta="-100%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="700"/>
</set>

logcat的

02-17 12:00:25.028 16696-16696/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.example.eivind.ticktick, PID: 16696
                                               java.lang.RuntimeException: Unknown animator name: ObjectAnimator

1 个答案:

答案 0 :(得分:0)

你只是想念objectAnimator元素

将ObjectAnimator更改为objectAnimator,就像这样

<强> RES /动画/ enter_from_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
<objectAnimator
    android:fromXDelta="100%" android:toXDelta="0%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="700"/>
</set>

<强> RES /动画/ exit_to_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
<objectAnimator
    android:fromXDelta="0%" android:toXDelta="-100%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="700"/>
</set>