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(){
ObjectAnimator animator = new ObjectAnimator().ofFloat(button,
"translationX", 0, 10, 20, 30, 40, 50);
animator.setDuration(3000);
animator.setRepeatCount(3);
animator.setRepeatMode(ObjectAnimator.REVERSE);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(button, "rotation",
0, 10, 20, 30, 40, 50);
animator2.setDuration(3000);
animator2.setRepeatCount(2);
animator2.setRepeatMode(ObjectAnimator.REVERSE);
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);
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);
AnimatorSet set = new AnimatorSet();
set.playTogether(animator, animator2, animator3, animator4);
set.start();
}
}