属性动画
1.ObjectAnimator
2.ObjectAnimator
3.AnimatorSet
4.TypeEvaluator
5.TimeInterpolator
6.API
1.ObjectAnimator
提供了ofInt、ofFloat、ofObject,这几个方法都是设置动画作用的元素、作用的属性、动画开始、结束、以及中间的任意个属性值。
使用方式:
ObjectAnimator anim1=ObjectAnimator.ofFloat(line1,"scaleY",1.0f,0.9f).setDuration(400);
ObjectAnimator anim2=ObjectAnimator.ofFloat(line1,"scaleX",1.0f,0.9f).setDuration(400);
ObjectAnimator anim3=ObjectAnimator.ofFloat(line1,"alpha",1.0f,0.5f).setDuration(400);
ObjectAnimator anim4=ObjectAnimator.ofFloat(line1,"TranslationY",0.0f,-(float)(0.05*lin1Height)).setDuration(400);
ObjectAnimator anim5=ObjectAnimator.ofFloat(line1,"RotationX",0f,30f).setDuration(200);
ObjectAnimator anim6=ObjectAnimator.ofFloat(line1,"RotationX",30f,0f).setDuration(200);
实现监听:
1.addListener()//监听开始,结束等
可以new AnimatorListenerAdapter()可选择开始,结束等等事件,也可以 AnimatorListener()全部事件一次性出来
2.addUpdateListener();//监听过程,可以通过该过程得到改变的值,可进行改变别的View状态。
如:
anim.addUpdateListener(new AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
float cVal = (Float) animation.getAnimatedValue();
view.setAlpha(cVal);
view.setScaleX(cVal);
view.setScaleY(cVal);
}
});
*实现一个动画更改多个效果:使用propertyValuesHolder
public void propertyValuesHolder(View view)
{
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f,
0f, 1f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f,
0, 1f);
PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f,
0, 1f);
ObjectAnimator.ofPropertyValuesHolder(view, pvhX, pvhY,pvhZ).setDuration(1000).start();
}
2.ValueAnimator实现动画
ValueAnimator:没有具体的执行某些属性变化,,而是通过这个可以设置移动的值,根据当前动画的计算值,来操作任何属性
例子:
ValueAnimator animator = ValueAnimator.ofFloat(0, mScreenHeight
- mBlueBall.getHeight());
animator.setTarget(mBlueBall);
animator.setDuration(1000).start();
animator.addUpdateListener(new AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
mBlueBall.setTranslationY((Float) animation.getAnimatedValue());
}
});
3.AnimatorSet
AnimatorSet 动画集
play和with 同步进行动画,如 下面的例子,anim1,anim2,anim3,anim4,anim5,anim7同步进行
before在什么后面进行 anim6在anim5后面进行
after 在什么之前进行
AnimatorSet set=new AnimatorSet();
set.play(anim1).with(anim2).with(anim3).with(anim4).with(anim5).with(anim7);
set.play(anim5).before(anim6);
set.play(anim8).after(anim5);//相当于楼上的
set.play(anim5).after(anim8);
set.start();
4.TypeEvaluator
TypeEvaluator 类型估值,主要用于设置动画操作属性的值
5.Time interpolation
Time interpolation 时间差值,乍一看不知道是什么,但是我说LinearInterpolator、AccelerateDecelerateInterpolator,大家一定知道是干嘛的了,定义动画的变化率。
感谢:张鸿翔 部分内容摘自http://blog.youkuaiyun.com/lmj623565791/article/details/38067475