布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/spalsh_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
定义一个SplashActivity来进行效果的实现
public class SplashActivity extends Activity {
private int height;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ImageView imageView = findViewById(R.id.spalsh_icon);
//创建一个方法,里面是我们的属性动画
//获取屏幕的尺寸
WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
//开始执行动画
startAnimator(imageView);
}
//定义动画
public void startAnimator(View view) {
//属性
//旋转
ObjectAnimator translationY = ObjectAnimator.ofFloat(view, "translationY", 0, height / 2);
//透明
ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
//缩放
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 2, 1);
//缩放
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 2, 1);
//旋转
ObjectAnimator rotation = ObjectAnimator.ofFloat(view, "rotation", 360);
//创建动画合集
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(translationY, alpha, scaleX, scaleY, rotation);
animatorSet.setDuration(3000);
animatorSet.start();
//监听
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
//动画结束
Toast.makeText(SplashActivity.this, "跳转", Toast.LENGTH_SHORT).show();
startActivity(new Intent (SplashActivity.this, MainActivity.class));
finish();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}