请务必查看ViewPropertyAnimator类及其方法。对于加速和弹跳等,有所谓的插值器,使动画更逼真/逼真。我能想到的最简单的方法是这样的:
假设您在这样的 xml 文件中有一个 RelativeLayout 作为父级和一个 ImageView 作为子级:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/your_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
然后在您的 Java 代码中像这样启动动画:
ImageView imageView = (ImageView) findViewById(R.id.your_image);
float bottomOfScreen = getResources().getDisplayMetrics()
.heightPixels - (imageView.getHeight() * 4);
//bottomOfScreen is where you want to animate to
imageView.animate()
.translationY(bottomOfScreen)
.setInterpolator(new AccelerateInterpolator())
.setInterpolator(new BounceInterpolator())
.setDuration(2000);
Run Code Online (Sandbox Code Playgroud)
这应该让你开始。