public class MainActivity extends AppCompatActivity { private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化控件 iv= (ImageView) findViewById(R.id.iv); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this,"点击了",Toast.LENGTH_SHORT).show(); } }); } public void trans(View view) { ObjectAnimator animator = ObjectAnimator.ofFloat(iv, "Y", 0, 300, 400, 600, 900, 1500); animator.setInterpolator(new AccelerateInterpolator()); //设置时间 animator.setDuration(5000); animator.start(); } public void alpha(View view) { ObjectAnimator alpha = ObjectAnimator.ofFloat(iv, "alpha", 0, 1); alpha.setDuration(3000); alpha.start(); } public void rotate(View view) { ObjectAnimator animator = ObjectAnimator.ofFloat(iv, "rotationY", 0, 360); animator.setDuration(5000); animator.start(); } public void scale(View view) { ObjectAnimator alpha = ObjectAnimator.ofFloat(iv, "scaleX", 1, 3); alpha.setDuration(3000); alpha.start(); } public void with(View view) { ObjectAnimator y = ObjectAnimator.ofFloat(iv, "Y", 0, 500, 800, 1300); ObjectAnimator alpha = ObjectAnimator.ofFloat(iv, "alpha", 0.5f, 1); ObjectAnimator rotationX = ObjectAnimator.ofFloat(iv, "rotationX", 0, 360); ObjectAnimator rotationY = ObjectAnimator.ofFloat(iv, "rotationY", 0, 360); ObjectAnimator scaleX = ObjectAnimator.ofFloat(iv, "scaleX", 0.5f, 2); ObjectAnimator scaleY = ObjectAnimator.ofFloat(iv, "scaleY", 0.5f, 2); //组合 AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(y).with(alpha).with(rotationX).with(rotationY).with(scaleX).with(scaleY); animatorSet.setDuration(5000); animatorSet.start(); animatorSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); } }
补间动画
最新推荐文章于 2022-11-18 15:42:25 发布