应用的动画将视图移动到屏幕顶部

问题描述

要查看我的湿度图像视图,我需要向下滚动一点。 当我应用此动画时:

ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(humidityImageView,View.Y,40);
objectAnimator.setDuration(2000);
objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
objectAnimator.start();

它从屏幕顶部开始,但不是从ConstraintLayout中湿度图像视图的位置开始。 如何使动画从初始视图位置开始?

解决方法

我所需要做的就是将View.Y替换为View.TRANSLATION_Y