package com.saiermeng.easypropertyanim;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
}
public void alpha(View view) {
ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "alpha", 0, 0.1f, 0.3f,
0.5f, 0.7f, 0.9f, 1.0f);
oa.setDuration(3000);
oa.setRepeatCount(2);
oa.setRepeatMode(ObjectAnimator.REVERSE);
oa.start();
}
public void rotate(View view) {
ObjectAnimator ra = ObjectAnimator.ofFloat(iv, "rotation", 0, 30, 60,
90, 120, 150, 180, 210, 240, 270, 300, 330, 360);
ra.setDuration(3000);
ra.setRepeatCount(2);
ra.setRepeatMode(ObjectAnimator.REVERSE);
ra.start();
}
public void scale(View view) {
ObjectAnimator sa = ObjectAnimator.ofFloat(iv, "scaleX", 0, 0.2f, 0.4f,
0.6f, 0.8f, 1.0f);
sa.setDuration(3000);
sa.setRepeatCount(2);
sa.setRepeatMode(ObjectAnimator.REVERSE);
sa.start();
ObjectAnimator say = ObjectAnimator.ofFloat(iv, "scaleY", 0, 0.2f, 0.4f,
0.6f, 0.8f, 1.0f);
say.setDuration(3000);
say.setRepeatCount(2);
say.setRepeatMode(ObjectAnimator.REVERSE);
say.start();
}
public void translate(View view) {
ObjectAnimator ta = ObjectAnimator.ofFloat(iv, "translationY", 0, 30, 60,
90);
ta.setDuration(3000);
ta.setRepeatCount(2);
ta.setRepeatMode(ObjectAnimator.REVERSE);
ta.start();
}
public void set(View view) {
AnimatorSet set = new AnimatorSet();
ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "alpha", 0, 0.1f, 0.3f,
0.5f, 0.7f, 0.9f, 1.0f);
oa.setDuration(3000);
oa.setRepeatCount(2);
oa.setRepeatMode(ObjectAnimator.REVERSE);
ObjectAnimator ra = ObjectAnimator.ofFloat(iv, "rotation", 0, 30, 60,
90, 120, 150, 180, 210, 240, 270, 300, 330, 360);
ra.setDuration(3000);
ra.setRepeatCount(2);
ra.setRepeatMode(ObjectAnimator.REVERSE);
ObjectAnimator sa = ObjectAnimator.ofFloat(iv, "scaleX", 0, 0.2f, 0.4f,
0.6f, 0.8f, 1.0f);
sa.setDuration(3000);
sa.setRepeatCount(2);
sa.setRepeatMode(ObjectAnimator.REVERSE);
ObjectAnimator ta = ObjectAnimator.ofFloat(iv, "translationY", 0, 30, 60,
90);
ta.setDuration(3000);
ta.setRepeatCount(2);
ta.setRepeatMode(ObjectAnimator.REVERSE);
set.playTogether(oa,ra,sa,ta);
set.start();
}
}