android动画
安卓开发中,为了给用户更好的使用体验,我们可以使用动画,下面谈谈自己对动画的简单的理解:
动画分类:
帧动画
View动画
属性动画
transition动画(转场动画)(基于属性动画?)
布局动画(LayoutTransition?)
帧动画
对应于AnimationDrawable类:
public class AnimationDrawable
extends DrawableContainer implements Runnable, Animatable
java.lang.Object
↳ android.graphics.drawable.Drawable
↳ android.graphics.drawable.DrawableContainer
↳ android.graphics.drawable.AnimationDrawable
简单的使用场景:
<!-- Animation frames are wheel0.png through wheel5.png
files inside the res/drawable/ folder -->
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/wheel0" android:duration="50" />
<item android:drawable="@drawable/wheel1" android:duration="50" />
<item android:drawable="@drawable/wheel2" android:duration="50" />
<item android:drawable="@drawable/wheel3" android:duration="50" />
<item android:drawable="@drawable/wheel4" android:duration="50" />
<item android:drawable="@drawable/wheel5" android:duration="50" />
</animation-list>
Here is the code to load and play this animation.
// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
官方链接:https://developer.android.google.cn/reference/android/graphics/drawable/AnimationDrawable.html
View动画
相关包:
android.view.animation
官方介绍:
https://developer.android.google.cn/reference/android/view/animation/package-summary.html
简单的使用例子:
animexample.xml
<set android:shareInterpolator="false">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="0.6"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700" />
<set android:interpolator="@android:anim/decelerate_interpolator">
<scale
android:fromXScale="1.4"
android:toXScale="0.0"
android:fromYScale="0.6"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="400"
android:fillBefore="false" />
<rotate
android:fromDegrees="0"
android:toDegrees="-45"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="400" />
</set>
</set>
mAnimation=AnimationUtils.load(mContext,R.anim.animexaple);
//mAnimation=new ScaleAnimation(mContext);
//mAnimation.setXX();
...
mView.startAnimation(mAnimation);
属性动画
相关包:android.animation
These classes provide functionality for the property animation system, which allows you to animate object properties of any type. int, float, and hexadecimal color values are supported by default. You can animate any other type by telling the system how to calculate the values for that given type with a custom TypeEvaluator.
For more information, see the Animation guide.
You can set many different types of interpolators (contained in android.view.animation), specify keyframes, or group animations to play sequentially or simultaneously (with AnimatorSet) to further control your animation behaviors.
官方介绍:
https://developer.android.google.cn/reference/android/animation/package-summary.html
怎么使用直接看官方文档,内容太多了!!
*Transition*
相关类:scene,transition,transitionmanager等等
相关包:android.transition
官方介绍:https://developer.android.google.cn/reference/android/transition/package-summary.html
布局动画
public class LayoutTransition
extends Object
java.lang.Object
↳ android.animation.LayoutTransition
This class enables automatic animations on layout changes in ViewGroup objects. To enable transitions for a layout container, create a LayoutTransition object and set it on any ViewGroup by calling setLayoutTransition(LayoutTransition). This will cause default animations to run whenever items are added to or removed from that container. To specify custom animations, use the setAnimator() method.
另外!!!
说到这个布局动画,layoutanimation又是什么鬼?和layouttransition有什么区别???没搞懂,用时再找找资料吧!!
可以看看这篇文章
唉,语文很渣,这文章质量简直没法看啊。。。