需求:
启动页:使用属性动画实现,3秒后自动跳转
(渐变、缩放、平移、旋转)
- activity_animation
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:src="@mipmap/ic_launcher_round" />
</RelativeLayout>
-AnimationActivity
public class AnimationActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation);
imageView = (ImageView) findViewById(R.id.img);
// 平移
ObjectAnimator translationY = ObjectAnimator.ofFloat(imageView, "translationY", 0, 500f);
ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1f);
ObjectAnimator rotation = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 2f, 1f);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 2f, 1f);
AnimatorSet animSet = new AnimatorSet();
animSet.playTogether(translationY, alpha, rotation, scaleY, scaleX);
animSet.setDuration(3000);
animSet.start();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(AnimationActivity.this, DetailsActivity.class));
finish();
}
}, 3000);
}