我想要执行 View 从其在屏幕上的当前位置到平滑滚动中剩余的 X 像素点的平移动画。我尝试通过以下方式做到这一点:
oldPosition = view.getLeft();
newPosition = oldPosition - secondview.getwidth();
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, newPosition,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
translateAnimation.setDuration(1000);
translateAnimation.reset();
view.clearAnimation();
view.setAnimation(translateAnimation);
但最终结果并不是从旧位置平滑滚动到新位置,而是看起来好像 View 滚动到屏幕外然后重新绘制。如何创建从正确的开始位置到正确的结束位置的平滑滚动?
最佳答案
我建议使用ObjectAnimator (或 ValueAnimator)...
例如this so answer应该会给你一个好的开始。
关于java - 将 View 从当前位置平滑滑动到左侧 X 像素的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28264751/