Android 属性动画

属性动画

package com.example.month.view;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.example.month.R;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //寻找控件
        ImageView img = (ImageView) findViewById(R.id.img);

        //组合动画
        //平移
        ObjectAnimator y = ObjectAnimator.ofFloat(img, "Y", 0, 800);
        //缩放
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 2, 1);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", 2, 1);
        //透明度
        ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 0, 1);
        //旋转
        ObjectAnimator rotationX = ObjectAnimator.ofFloat(img, "rotationX", 0, 360);
        ObjectAnimator rotationY = ObjectAnimator.ofFloat(img, "rotationY", 0, 360);
        //组合
        AnimatorSet animatorSet = new AnimatorSet();
        //组合在一起
        animatorSet.play(y).with(scaleX).with(scaleY).with(alpha).with(rotationX).with(rotationY);
        animatorSet.setDuration(3000);
        animatorSet.start();
        //跳转页面
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                Intent it = new Intent(MainActivity.this,Commodity.class);
                startActivity(it);
                finish();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

    }
}

猜你喜欢

转载自blog.csdn.net/wrpbk/article/details/79100736