属性动画,平移,旋转,渐变,一个搞定所有动画

package bwie.com.day8_test;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {

    private ImageView viewById;
    private Intent intent;
    private ObjectAnimator scaleX;
    private AnimatorSet animatorSet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewById = findViewById(R.id.iv);
        //平移
        ObjectAnimator objectAnimator = 
        ObjectAnimator.ofFloat(viewById, "translationY",viewById.getTranslationY(), 800);
        //旋转
        ObjectAnimator objectAnimator1= ObjectAnimator.ofFloat(viewById,"rotation",0,360);
        //渐变
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(viewById,"alpha",0,1,0,1);
        //绕什么轴旋转
        ObjectAnimator ObjectAnimator3 =
         ObjectAnimator.ofFloat(viewById, "scaleX", 0, 1);
        animatorSet = new AnimatorSet();
//让动画连在一起      
  animatorSet.play(objectAnimator)
.with(objectAnimator1)
.with(objectAnimator2)
   .with(ObjectAnimator3);
//动画的时间
        animatorSet.setDuration(5000);
        animatorSet.start();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                intent = new Intent(MainActivity.this, HomeActivity.class);
                startActivity(intent);
            }
        },5000);
    }
}

你可能感兴趣的:(属性动画,平移,旋转,渐变,一个搞定所有动画)