public class MainActivity extends AppCompatActivity implements View.OnClickListener { private ImageButton imageButton; private Button dan; private Button zhuan; private Button yi; private Button zuhe; private Button suo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Animator animator = AnimatorInflater.loadAnimator(this, R.animator.objectanimator); animator.setTarget(imageButton); animator.start(); initView(); } private void initView() { imageButton = (ImageButton) findViewById(R.id.imageButton); dan = (Button) findViewById(R.id.button); zhuan = (Button) findViewById(R.id.button2); yi = (Button) findViewById(R.id.button3); zuhe = (Button) findViewById(R.id.button4); suo = (Button) findViewById(R.id.button5); dan.setOnClickListener(this); zhuan.setOnClickListener(this); yi.setOnClickListener(this); zuhe.setOnClickListener(this); suo.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.button: ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageButton, "alpha", 1f, 0f, 1f); animator1.setDuration(5000); animator1.start(); break; case R.id.button2: ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageButton, "rotationX", 0f, 360.0f); animator2.setDuration(5000); animator2.start(); break; case R.id.button3: ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageButton, "translationY", 0f, 500f); animator3.setDuration(5000); animator3.start(); break; case R.id.button4: AnimatorSet set = new AnimatorSet(); ObjectAnimator animator22 = ObjectAnimator.ofFloat(imageButton, "rotationX", 0f, 360.0f); ObjectAnimator animator33 = ObjectAnimator.ofFloat(imageButton, "translationX", -500f, 0,500f,0f); set.playTogether(animator22,animator33); set.setDuration(5000); set.start(); break; case R.id.button5: ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageButton, "scaleX", 1f, 0f,1f); scaleX.setDuration(5000); scaleX.start(); break; } } }
属性动画
最新推荐文章于 2024-01-09 01:05:38 发布