public class PropertyAnimActivity extends Activity {
private ImageView mIVHandle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_properties_anim);
mIVHandle = (ImageView) findViewById(R.id.iv_hand);
}
//位移
public void clickTraslate(View view){
ObjectAnimator animator = ObjectAnimator.ofFloat(mIVHandle, "translationX", 0, 200);
animator.setDuration(3000);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.start();
}
//缩放
public void clickScale(View view){
//mIVHandle.setPivotX(0.5f);
//mIVHandle.setPivotY(0.5f);
ViewHelper.setPivotX(mIVHandle, 0.5f);
ViewHelper.setPivotY(mIVHandle, 0.5f);
ObjectAnimator animator = ObjectAnimator.ofFloat(mIVHandle, "scaleX", 0, 2);
animator.setDuration(3000);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.start();
}
//旋转
public void clickRotate(View view){
//ObjectAnimator animator = ObjectAnimator.ofFloat(mIVHandle, "rotationX", 0, 360);
ObjectAnimator animator = ObjectAnimator.ofFloat(mIVHandle, "rotation", 0, 360);
animator.setDuration(3000);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.start();
}
//透明
public void clickAlpha(View view){
ObjectAnimator animator = ObjectAnimator.ofFloat(mIVHandle, "alpha", 0, 1);
animator.setDuration(3000);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.start();
}
//集合
public void clickSet(View view){
AnimatorSet set = new AnimatorSet();
ObjectAnimator alpha = ObjectAnimator.ofFloat(mIVHandle, "alpha", 0, 1);
ObjectAnimator rotation = ObjectAnimator.ofFloat(mIVHandle, "rotation", 0, 360);
ObjectAnimator scale = ObjectAnimator.ofFloat(mIVHandle, "scaleX", 0, 2);
//1.按循序播放
set.playSequentially(alpha, rotation, scale);
//2.按先后播放
set.play(alpha).after(rotation).before(scale);
//3.同时播放
set.playTogether(alpha, rotation, scale);
set.setDuration(2000);
set.start();
}
//color
public void clickColor(View view){
//setBackgroundColor
ObjectAnimator animator = ObjectAnimator.ofObject(mIVHandle, "backgroundColor", new ArgbEvaluator(), Color.RED, Color.BLUE);
animator.setDuration(3000);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.start();
}
//xml
public void clickXml(View view){
Animator animator = AnimatorInflater.loadAnimator(this, R.animator.translator);
animator.setTarget(mIVHandle);
animator.start();
//AnimatorInflater.loadAnimator(this, R.animator.scale).setTarget(mIVHandle).start();
}
}