Android 使用ObjectAnimation从右向左滑动

Android 使用ObjectAnimation从右向左滑动,android,android-animation,objectanimator,Android,Android Animation,Objectanimator,由于YouTube链接中给出的示例代码,我可以从左向右播放幻灯片: 但是我不能做从右到左的动画。我试着在下面的代码中加一个“-”(负号),但它不起作用,它给了我一个错误: 运算符“-”不能应用于 'android.util.Property 有什么方法可以在活动中执行此操作吗?您应该处理该值,而属性名称应该保持不变: ObjectAnimator translateAnimation = ObjectAnimator.ofFloat(view, View.TRANSLA

由于YouTube链接中给出的示例代码,我可以从左向右播放幻灯片:

但是我不能做从右到左的动画。我试着在下面的代码中加一个“-”(负号),但它不起作用,它给了我一个错误:

运算符“-”不能应用于 'android.util.Property


有什么方法可以在活动中执行此操作吗?

您应该处理该值,而属性名称应该保持不变:

ObjectAnimator translateAnimation =
            ObjectAnimator.ofFloat(view, View.TRANSLATION_X, -view.getWidth());
    translateAnimation.start();
    translateAnimation.setRepeatCount(1);
    translateAnimation.setRepeatMode(ValueAnimator.REVERSE);

我试过这样做,但它的工作,但为什么它去太多的左边,并消失了。它不应该回到正常的位置吗?哦,顺便说一句,我试着不用“setRepeatCount”和“setRepeatMode”方法。我试着用不同的按钮来做。800应该是从视图宽度计算出来的参数。很抱歉,我不明白你的意思。
ObjectAnimator translateAnimation =
            ObjectAnimator.ofFloat(view, View.TRANSLATION_X, -view.getWidth());
    translateAnimation.start();
    translateAnimation.setRepeatCount(1);
    translateAnimation.setRepeatMode(ValueAnimator.REVERSE);