美文网首页
Android中Animation

Android中Animation

作者: 晓晓桑 | 来源:发表于2023-03-12 16:14 被阅读0次

    Animation从总体来说可以分为两类:

    1.Tweened Animations:该类提供了旋转,移动,伸展,淡入淡出等效果

    Tweened Animations也有四种类型:

    1. Alpha:淡入淡出效果
      
    2. [Scale](https://so.csdn.net/so/search?q=Scale&spm=1001.2101.3001.7020):缩放效果
      
    3. Rotate:旋转效果
      
    4. Translate:移动效果
      

    设置动画有两种方式:在xml文件中或者在Java代码中

    在XML中设置动画效果步骤:

    1. 在res文件夹下新建一个名为anim的文件夹
      
    2. 创建xml文件,并首先加入set标签(set标签就相当于Java代码中的AnimationSet)
      
    3. 在Set标签中加入alpha,scale,rotate,translate标签(相当于Java代码中的AlphaAnimation,ScaleAnimation,RotateAnimation,TranslateAnimation)
      
    4. 在Java代码中使用AnimationUtils的loadAnimation方法来加载XML文件,并得到一个Animation对象
      
    5. 使用控件的startAnimation()方法执行这个Animation对象
      

    那么通用的属性:

    • android:duration:设置动画持续时间
    • android:fillAfter:如果fillAfter设为true,则动画执行后,控件将停留在动画结束的状态
    • android:fillBefore:如果fillBefore设为true,则动画执行后,控件将回到动画开始的状态
    • android:startOffset(long startOffset):设置动画执行之前等待的时间(单位:毫秒)
    • android:repeatCount(int repeatCount):设置动画重复的次数
    • android:interpolator:设置动画的变化速度,其值:

    Android:interpolator="@android:anim/accelerate_decelerate_interpolator":先加速,后减速

    android:interpolator="@android:anim/accelerate_interpolator":加速

    android:interpolator="@android:anim/decelerate_interpolator":减速

    android:interpolator="@android:anim/cycle_Interpolator":动画循环播放特定次数,速率改变沿着正弦曲线

    android:interpolator="@android:anim/linear_Interpolator":匀速

    相关文章

      网友评论

          本文标题:Android中Animation

          本文链接:https://www.haomeiwen.com/subject/kafqrdtx.html