Android 查看顶部父项的动画

Android View animation to top parent

我的目标是使当前视图从当前位置(中心)到其父级的上边框动画化。那可能吗?我已经尝试了下一个代码,但问题是我的视图在动画后消失了:

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 文档了解以后的动画,它非常易于使用,可以节省大量代码。