简体   繁体   中英

Custom Translation Animation not working correctly

I am attempting to animate a part of an android app, unfortunately I can not get my animation to work correctly.

The following xml file works correctly, but it has an absolute reference rather than a relative one.

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" 
        android:propertyName="x" 
        android:valueType="floatType"
        android:valueTo="0" 
        android:valueFrom="100"
        android:duration="800"
/>

When I try aa relative reference, like the following, the animation is not correct. It produces the correct screen, but the fragment just appears, rather than sliding in from the left.

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:propertyName="translationX" 
    android:fromXDelta="100%"
    android:toXDelta="0%"
    android:duration="500"/>

Does anyone have the solution to this?

Reverse your fromXdelta and toxDelta values. You are applying the 100% change at the start of the animation and 0% at the end.

From: http://developer.android.com/reference/android/view/animation/TranslateAnimation.html

fromXValue Change in X coordinate to apply at the start of the animation.

toXValue Change in X coordinate to apply at the end of the animation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM