话android动画

android动画

安卓开发中,为了给用户更好的使用体验,我们可以使用动画,下面谈谈自己对动画的简单的理解:

动画分类:

  • 帧动画

  • View动画

  • 属性动画

  • transition动画(转场动画)(基于属性动画?)

  • 布局动画(LayoutTransition?)

帧动画

对应于AnimationDrawable类:

public class AnimationDrawable 
extends DrawableContainer implements Runnable, Animatable

java.lang.Objectandroid.graphics.drawable.Drawableandroid.graphics.drawable.DrawableContainerandroid.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

布局动画

LayoutTransition

public class LayoutTransition 
extends Object 

java.lang.Objectandroid.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有什么区别???没搞懂,用时再找找资料吧!!
可以看看这篇文章

唉,语文很渣,这文章质量简直没法看啊。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值