我的目标是将当前 View 从其当前位置(中心)动画化到其父级的顶部边框。那可能吗?我已经尝试了下一个代码,但问题是我的 View 在动画后消失了:
Animation bottomUp = AnimationUtils.loadAnimation(context, R.anim.bottom_up);
popup.startAnimation(bottomUp);
和
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%"
android:toYDelta="0%"
android:fillAfter="true"
android:duration="500"/>
</set>
最佳答案
这可以在 Java 中使用 ViewPropertyAnimator 轻松完成。
popup.animate().translationY(0).setDuration(500); // 0 is top of Y axis
动画总是从当前位置开始。
检查 ViewPropertyAnimator future 动画的文档,它非常易于使用,可以为您节省大量代码。
关于Android 查看动画到顶部父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38391866/