ObjectAnimator.ofFloat(iv_share,"rotationX",0.0f,360.0f).setDuration(500).start();
ObjectAnimator.ofFloat(iv_share,"rotationY",0.0f,360.0f).setDuration(500).start();
ObjectAnimator.ofFloat(iv_share,"rotation",0.0f,360.0f).setDuration(500).start();
ObjectAnimator.ofFloat(iv_share,"TranslationY",-200).setDuration(2000).start();
效果5:左右方向移动
ObjectAnimator.ofFloat(iv_share,"scaleX",0.0f,3.0f).setDuration(500).start();
效果7:y轴方向缩放
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:propertyName="scaleX"
android:valueFrom="1.0"
android:valueTo="2.0"
android:valueType="floatType"
>
</objectAnimator>
Animator anima = AnimatorInflater.loadAnimator(MainActivity.this,R.animator.object_animator);三:属性动画之AnimatorSet
anima.setTarget(iv_share);
anima.start();
代码形式:
ObjectAnimator animator1 = ObjectAnimator.ofFloat(iv_share,"translationX",300f);xml形式:
ObjectAnimator animator2 = ObjectAnimator.ofFloat(iv_share,"scaleX",1f,0f,1f);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(iv_share,"scaleY",1f,0f,1f);
AnimatorSet set = new AnimatorSet();
set.setDuration(3000);
//一起执行
// set.playTogether(animator1,animator2,animator3);
//依次执行
set.playSequentially(animator1,animator2,animator3);
//先执行2后执行1
// set.play(animator1).after(animator2);
//1,2一块执行
// set.play(animator1).with(animator2);
set.start();
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together"
>
<objectAnimator
android:propertyName="scaleX"
android:duration="1000"
android:valueFrom="0.0f"
android:valueTo="1.0f"
android:repeatCount="1"
android:valueType="floatType"
/>
<objectAnimator
android:duration="1000"
android:propertyName="rotation"
android:interpolator="@android:interpolator/linear"
android:valueFrom="0"
android:valueTo="359"
android:valueType="floatType"
android:repeatCount="-1"
/>
</set>
AnimatorSet set = (AnimatorSet) AnimatorInflater.loa,但是dAnimator(MainActivity.this,R.animator.animatorset_animator);四:属性动画之PropertyValuesHolder
set.setTarget(iv_share);
set.start();
在属性动画中,如果针对同一对象的多个属性,要同时左右多种动画,可以使用PropertyValuesHolder来实现,这个与上面的区别是不能实现顺序控制
PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("translationX",300f);五:属性动画之ValueAnimator
PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("scaleX",1f,0,1f);
PropertyValuesHolder p3 = PropertyValuesHolder.ofFloat("scaleY",1f,0,1f);
ObjectAnimator.ofPropertyValuesHolder(iv_share,p1,p2,p3).setDuration(1000).start();
1.ValueAnimator本身不提供任何动画效果,它更像一个数值发生器,用来产生具有一定规律的数字,从而让调用者来控制动画的实现过程,一般情况下,在ValueAnimator的AnimatorUpdateListener中监听数字的变换,从而进行动画的操作
ValueAnimator animator = ValueAnimator.ofFloat(1,100);2.可以用动画来做一个背景色颜色的渐变
animator.setTarget(iv_share);
animator.setRepeatCount(-1);
animator.setDuration(1000).start();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
iv_share.setTranslationX(value);
}
});
//改变背景颜色变换,颜色值可以输入多个进行切换,时间平分六:属性动画之动画的监听
ValueAnimator colorAnim = ObjectAnimator.ofInt(listView,"backgroundColor",0x22222222,0xFF8080FF,0x00001111,0x78787878);
colorAnim.setDuration(3000);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.RESTART);
colorAnim.start();
ObjectAnimator object = ObjectAnimator.ofFloat(iv_share, "rotationY", 0.0f, 360.0f);
object.setDuration(2000);
object.start();
//第一种,可以自己选择覆写哪个方法
object.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
Toast.makeText(MainActivity.this, "停止执行属性动画1", Toast.LENGTH_SHORT).show();
}
});
//第二种,全部重写
object.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
//动画开始执行时
Toast.makeText(MainActivity.this, "开始执行属性动画", Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationEnd(Animator animation) {
//动画结束执行时
Toast.makeText(MainActivity.this, "停止执行属性动画", Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationCancel(Animator animation) {
//放弃执行
Toast.makeText(MainActivity.this, "放弃执行属性动画", Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationRepeat(Animator animation) {
//动画重复执行
Toast.makeText(MainActivity.this, "重复执行属性动画", Toast.LENGTH_SHORT).show();
}
});
}