属性动画和补间动画
程序员文章站
2022-03-25 18:44:51
...
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button bt_tou;
private Button bt_xuan;
private Button bt_suo;
private Button bt_ping;
private ImageView img;
private Button bt_zong;
private Button bt_tou1;
private Button bt_xuan1;
private Button bt_suo1;
private Button bt_ping1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
bt_tou = (Button) findViewById(R.id.bt_tou);
bt_xuan = (Button) findViewById(R.id.bt_xuan);
bt_suo = (Button) findViewById(R.id.bt_suo);
bt_ping = (Button) findViewById(R.id.bt_ping);
img = (ImageView) findViewById(R.id.img);
bt_tou.setOnClickListener(this);
bt_xuan.setOnClickListener(this);
bt_suo.setOnClickListener(this);
bt_ping.setOnClickListener(this);
bt_zong = (Button) findViewById(R.id.bt_zong);
bt_zong.setOnClickListener(this);
bt_tou1 = (Button) findViewById(R.id.bt_tou1);
bt_tou1.setOnClickListener(this);
bt_xuan1 = (Button) findViewById(R.id.bt_xuan1);
bt_xuan1.setOnClickListener(this);
bt_suo1 = (Button) findViewById(R.id.bt_suo1);
bt_suo1.setOnClickListener(this);
bt_ping1 = (Button) findViewById(R.id.bt_ping1);
bt_ping1.setOnClickListener(this);
}
public void mei(View view) {
Toast.makeText(this, "我美不美", Toast.LENGTH_SHORT).show();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_tou:
ObjectAnimator animator = ObjectAnimator.ofFloat(img, "alpha", new float[]{0.0f, 0.5f, 1.0f});
animator.setDuration(3000);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.start();
break;
case R.id.bt_xuan:
ObjectAnimator animator1 = ObjectAnimator.ofFloat(img, "rotation", new float[]{0, 360});
animator1.setDuration(3000);
animator1.setRepeatMode(ObjectAnimator.REVERSE);
animator1.start();
break;
case R.id.bt_suo:
ObjectAnimator animator2 = ObjectAnimator.ofFloat(img, "scaleX", new float[]{1f, 3f, 6f, 3f, 1f});
animator2.setDuration(3000);
animator2.setRepeatMode(ObjectAnimator.REVERSE);
animator2.start();
break;
case R.id.bt_ping:
ObjectAnimator animator3 = ObjectAnimator.ofFloat(img, "translationY", new float[]{-300f});
animator3.setDuration(3000);
animator3.setRepeatMode(ObjectAnimator.REVERSE);
animator3.start();
break;
case R.id.bt_zong:
AnimatorSet set = new AnimatorSet();
ObjectAnimator animator4 = ObjectAnimator.ofFloat(img, "rotation", new float[]{0, 360});
animator4.setDuration(3000);
ObjectAnimator animator5 = ObjectAnimator.ofFloat(img, "scaleX", new float[]{1f, 3f, 6f, 3f, 1f});
animator5.setDuration(3000);
ObjectAnimator animator6 = ObjectAnimator.ofFloat(img, "translationY", new float[]{-300f});
animator6.setDuration(3000);
ObjectAnimator animator7 = ObjectAnimator.ofFloat(img, "alpha", new float[]{0.0f, 0.5f, 1.0f});
animator7.setDuration(3000);
set.playSequentially(animator4, animator5, animator6, animator7);
set.start();
break;
case R.id.bt_tou1:
AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
alphaAnimation.setDuration(3000);
img.startAnimation(alphaAnimation);
break;
case R.id.bt_xuan1:
RotateAnimation rotateAnimation = new RotateAnimation(0, 90, 250, 350);
rotateAnimation.setDuration(3000);
img.startAnimation(rotateAnimation);
break;
case R.id.bt_suo1:
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 3f, 6f, 3f);
scaleAnimation.setDuration(3000);
img.startAnimation(scaleAnimation);
break;
case R.id.bt_ping1:
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, 200);
animation.setDuration(3000);
img.startAnimation(animation);
break;
}
}
}
上一篇: 免费手机号码归属地API查询接口和PHP使用实例分享_PHP教程
下一篇: 补间动画和属性动画
推荐阅读