视图上的滑入和滑出动画交替地将视图从其原始位置移开

Slide in and slide out animation on a view alternately displaces the view from its original position

我有一个视图和两个按钮,用于将视图向上滑动到屏幕,另一个按钮用于将其向下滑动。但是,如果我一直交替按下按钮,视图不会 return 到其原始位置,而是 displaced.Here 是代码

//button 1
Interpolator interpolator=new OvershootInterpolator();
        loginOptionsSheet.animate().translationYBy(-loginOptionsSheet.getHeight()).setDuration(550).setInterpolator(interpolator)
                .start();

//button 2
Interpolator interpolator=new FastOutLinearInInterpolator();
        loginOptionsSheet.animate().translationYBy(683).setDuration(300).setInterpolator(interpolator)
                .start();

当您继续按下按钮时,您将在动画制作过程中重新开始动画,并且由于您使用的是 translationYBy,因此 "origin" 会在动画重新开始时继续移动。 来自文档

The amount to be animated by, as an offset from the current value

所以改用 translationY

The value to be animated to

请注意,您必须更改您的值,因为您现在要转换为绝对位置,而不是输入要更改的相对量。