属性动画的使用
程序员文章站
2022-05-02 22:17:35
...
public class SplashActivity extends AppCompatActivity {
private int width;
private int height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash2);
//获取屏幕宽高
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
width = wm.getDefaultDisplay().getWidth();
height = wm.getDefaultDisplay().getHeight();
//初始化页面
initViews();
}
private void initViews() {
ImageView imageView=findViewById(R.id.splash_pic);
//属性动画
ObjectAnimator translationY = ObjectAnimator.ofFloat(imageView, "translationY", 0, height / 2);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 2, 1);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 2, 1);
ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 0, 1);
ObjectAnimator rotation = ObjectAnimator.ofFloat(imageView, "rotation", 360);
//添加到动画集合
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(translationY,scaleX,scaleY,alpha,rotation);
//设置
animatorSet.setDuration(3000);
animatorSet.start();
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
//动画结束的时候,跳转页面
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}
上一篇: python 邮件发送