欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

动画属性

程序员文章站 2022-03-02 19:37:43
...

public class MainActivity extends AppCompatActivity {

private ImageView iv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //获取资源id
    iv=findViewById(R.id.iv);
    //初始化数据
    initData();
}
/**
 * 初始化数据
 */
private void initData() {
    getSupportActionBar().hide();//隐藏标题栏
    DisplayMetrics displayMetrics=getResources().getDisplayMetrics();
    int height = displayMetrics.heightPixels;//屏幕高度
    //缩放
    ObjectAnimator objectAnimator1=ObjectAnimator.ofFloat(iv,"scaleX",2,1);
    //渐变
    ObjectAnimator objectAnimator2=ObjectAnimator.ofFloat(iv,"alpha",0,1);
    //旋转
    ObjectAnimator objectAnimator3=ObjectAnimator.ofFloat(iv,"rotation",0,360);
    //移动
    ObjectAnimator objectAnimator4=ObjectAnimator.ofFloat(iv,"translationY",0,height/2-iv.getHeight()/2);
    //组合
    AnimatorSet set = new AnimatorSet();
    set.play(objectAnimator1).with(objectAnimator2).with(objectAnimator3).with(objectAnimator4);
    //设置时间
    set.setDuration(3000);
    //开启
    set.start();
    ///动画执行监听
    set.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            //跳转页面
            startActivity(new Intent(MainActivity.this,showActivity.class));
            finish();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
}

}

上一篇: 属性动画

下一篇: python基础day03