Android 动画之补间动画

Android动画系列:

在Android中,动画可以分为三种模式,View Animation、Frame Animation、Property Animation,其中Frame Animation又是View Animation一种特殊形式,只不过它和平移、旋转等常见的View Animation在表现形式上略有不同。

View Animation

View Animation又称为Tween Animation,即补间动画,它通过对场景里的不断做图像变换(平移、缩放、旋转、透明度)从而产生动画,它是一种渐进式动画,并且View Animation支持自定义。

View animation只能应用于View对象,而且只支持一部分属性,如支持缩放旋转而不支持背景颜色的改变。

而且对于View animation,它只是改变了View对象绘制的位置,而没有改变View对象本身,比如,你有一个Button,坐标(100,100),Width:200,Height:50,而你有一个动画使其变为Width:100,Height:100,你会发现动画过程中触发按钮点击的区域仍是(100,100)-(300,150)。
View Animation的四种变换效果对应着Animation的四个子类AlphaAnimation(透明度)、TranslateAnimation(平移)、ScaleAnimation(缩放)、RotateAnimation(旋转)。

这里写图片描述

常用API

常量

  • int ABSOLUTE:指定的尺寸是象素的绝对数目
  • int INFINITE:无限重复
  • int RELATIVE_TO_PARENT:指定的浮动维度,并应进行动画的高度或宽度对象的与父控件相应相乘
  • int RELATIVE_TO_SELF:指定的浮动维度,并应进行动画的高度或宽度对象的与本身相应相乘
  • int RESTART:当动画到达末尾和重复次数是无限REPEATER或正值,动画从头重新开始
  • int REVERSE:当动画到达末尾和重复次数是无限REPEATER或正值,动画向后(然后再向前)播放
  • int START_ON_FIRST_FRAME:可以作为开始时间,指示的开始时间应该是当getTransformation(长,变换)被调用用于第一动画帧的当前时间
  • int ZORDER_BOTTOM:动画在其他动画执行后再执行
  • int ZORDER_NORMAL:动画保持当前Z顺序
  • int ZORDER_TOP:动画优于其他动画执行

常用属性及方法

XML属 性:android:detachWallpaper          
关联方法:setDetachWallpaper(boolean)          
注释说明:特殊选项窗口动画:如果这个窗口是墙纸的顶部,墙纸不与窗口同时动画                            

XML属 性:android:duration               
关联方法:setDuration(long)                  
注释说明:动画执行时间                               

XML属 性:android:fillAfter                  
关联方法:setFillAfter(boolean)           
注释说明:如果fillAfter的值为true,则动画执行后,控件将停留在执行结束的状态                               

XML属 性:android:fillBefore               
关联方法:setFillBefore(boolean)         
注释说明:如果fillBefore的值为true,则动画执行后,控件将回到动画执行之前的状态                                

XML属 性:android:fillEnabled              
关联方法:setFillEnabled(boolean)            
注释说明:如果设置为true,将fillBefore设置考虑在内                           

XML属 性:android:interpolator           
关联方法:setInterpolator(Interpolator)      
注释说明:设置动画的变化速率                          

XML属 性:android:repeatCount                  
关联方法:setRepeatCount(int)                  
注释说明:设置动画重复执行的次数                                

XML属 性:android:repeatMode                   
关联方法:setRepeatMode(int)             
注释说明:当到达结束和重复计数大于0或无穷大,定义动画行为。                                

XML属 性:android:startOffset                  
关联方法:setStartOffset(long)             
注释说明:设置动画执行之前的等待时间  
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在Android Studio中使用补间动画实现菠萝动画的步骤: 1. 在res/drawable文件夹下创建一个animation-list资源文件,命名为pineapple_animation.xml,代码如下: ```xml <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/pineapple1" android:duration="200" /> <item android:drawable="@drawable/pineapple2" android:duration="200" /> <item android:drawable="@drawable/pineapple3" android:duration="200" /> <item android:drawable="@drawable/pineapple4" android:duration="200" /> <item android:drawable="@drawable/pineapple5" android:duration="200" /> <item android:drawable="@drawable/pineapple6" android:duration="200" /> <item android:drawable="@drawable/pineapple7" android:duration="200" /> <item android:drawable="@drawable/pineapple8" android:duration="200" /> </animation-list> ``` 2. 在布局文件中添加一个ImageView控件,并设置其src属性为pineapple_animation.xml,代码如下: ```xml <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pineapple_animation" /> ``` 3. 在Activity中获取ImageView控件,并将其转换为AnimationDrawable类型,然后调用start()方法开始播放动画,代码如下: ```java ImageView imageView = findViewById(R.id.imageView); AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable(); animationDrawable.start(); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值