public class MainActivity extends Activity {
private Button button;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
change();
}
int count = 0;
public void click(View view) {
count++;
if(count==1){
Toast.makeText(this, "你再点下试试?!", 0).show();
change();
}
if(count==2){
Toast.makeText(this, "还真点啊,敢不敢再点?", 0).show();
change();}
if(count==3){
Toast.makeText(this, "好吧,你再点下看?", 0).show();
change();}
if(count==4){
Toast.makeText(this, "无所谓了,随便点吧", 0).show();
change();}
}
public void change(){
/*
* 参数1:要变化的控件UI
* 参数2:要怎么变
* 参数3:变化的过程 ,可变参数
*/
// 平移
// bt.TRANSLATION_X
ObjectAnimator animator = new ObjectAnimator().ofFloat(button,
"translationX", 0, 10, 20, 30, 40, 50);
// 总时常,周期
animator.setDuration(3000);
// 重复的次数
animator.setRepeatCount(3);
// 重复的类型
animator.setRepeatMode(ObjectAnimator.REVERSE);
// 启动
// animator.start();
// 旋转
// bt.setRotation(rotation)
ObjectAnimator animator2 = ObjectAnimator.ofFloat(button, "rotation",
0, 10, 20, 30, 40, 50);
animator2.setDuration(3000);
animator2.setRepeatCount(2);
animator2.setRepeatMode(ObjectAnimator.REVERSE);
// animator2.start();
// 缩放
// bt.setScaleX(scaleX)
ObjectAnimator animator3 = ObjectAnimator.ofFloat(button, "scaleX", 0f,
0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.8f, 1f);
animator3.setDuration(3000);
animator3.setRepeatCount(2);
animator3.setRepeatMode(ObjectAnimator.REVERSE);
// animator3.start();
// 透明
// bt.setAlpha(alpha)
ObjectAnimator animator4 = ObjectAnimator.ofFloat(button, "alpha", 0f,
0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.8f, 1f);
animator4.setDuration(3000);
animator4.setRepeatCount(2);
animator4.setRepeatMode(ObjectAnimator.REVERSE);
// animator4.start();
//动画集合
AnimatorSet set = new AnimatorSet();
// 一起玩,一起嗨
set.playTogether(animator, animator2, animator3, animator4);
set.start();
}
}
属性动画
最新推荐文章于 2024-01-09 01:05:38 发布