简体   繁体   English

自定义翻译动画无法正常工作

[英]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. 我正在尝试为Android应用程序的一部分制作动画,但是我无法使我的动画正常工作。

The following xml file works correctly, but it has an absolute reference rather than a relative one. 下面的xml文件可以正常工作,但是它具有绝对引用而不是相对引用。

<?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. 反转fromXdelta和toxDelta值。 You are applying the 100% change at the start of the animation and 0% at the end. 您将在动画开始时应用100%的更改,并在结束时应用0%的更改。

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

fromXValue Change in X coordinate to apply at the start of the animation. fromXValue更改X坐标以在动画开始时应用。

toXValue Change in X coordinate to apply at the end of the animation. toXValue更改X坐标以应用于动画的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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