缺点:并没有真正持久改变View的属性,就是说它内部没有一个去记录动画行为的机制;
帧动画:指的是一帧一帧播放的动画 实现:通过animation-list来实现,写法如下:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:duration="200" android:drawable="@drawable/ic_launcher"/> <item android:duration="200" android:drawable="@drawable/ic_launcher"/> <item android:duration="200" android:drawable="@drawable/ic_launcher"/> </animation-list>具体实现的类:ObjectAnimator; 问题是: ObjectAnimator只能是3.0之后才有,那么我们如果想让属性动画兼容低版本,那么一般
使用NineOldAnidroid.jar来实现属性动画用法: ViewPropertyAnimator.animate(text).rotationBy(180)
.setDuration(500) .start();//如果想在低版本直接操作view的属性,则用如下方法 ViewHelper.setScaleX(text, 0);
ValueAnimator: 它只是帮我们定义了动画的执行流程,但是没有帮我们实行具体的动画逻辑,
我们需要监听动画的进度,然后在回调方法中进行自定义的动画逻辑;
用法:
ValueAnimator animator = ValueAnimator.ofInt(100,1000); //监听动画执行的进度 animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { int animatedValue = (Integer) animator.getAnimatedValue(); // Log.e("tag", "animatorValue:"+animatedValue); //根据动画值的变化进行我们的动画逻辑 // LayoutParams params = text.getLayoutParams(); // params.height = animatedValue; // text.setLayoutParams(params); text.setText(animatedValue+""); } }); animator.setDuration(1500); animator.setStartDelay(1000); animator.start();