布局动画介绍

布局动画是渐变动画,android通过改变UI的属性(大小、位置、透明度等)来实现动画效果,每个view都对应一个矩阵来控制该view显示的位置,通过不同的方式来改变该控制矩阵就可以实现动画效果,例如旋转、移动、缩放等.

android.view.animation.Animation类代表所有动画变换的基类,其中5个实现类如下:

  1: AlphaAnimation:实现alpha渐变,可以使界面逐渐消失或者逐渐显现
  2: TranslateAnimation:实现位置移动渐变,需要指定移动的开始和结束坐标 
  3:  ScaleAnimation: 实现缩放渐变,可以指定缩放的参考点
  4: RotateAnimation:实现旋转渐变,可以指定旋转的参考点,默认值为(0,0)左上角。
  5: AnimationSet: 代表上面的渐变组合
一个和渐变动画效果关系比较密切的类android.view.animation.Interpolator,该类定义了渐变动画改变的速率,可以设置为加速变化、减速变化或者重复变化.

 

如下介绍前4种动画的实现:

1:AlphaAnimation:在res/anim/下新建alpha_animation.xml文件,文件如下:

<alpha       

xmlns:android="http://schemas.android.com/apk/res/android"     

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

android:fromAlpha="0.0"       

android:toAlpha="1.0"       

android:duration="1000" />   

 

fromAlpha=0.0指从完全透明到toAlpha="1.0完全不透明,duration指渐变的时间

 

2:TranslateAnimation:在res/anim/下新建translate_animation.xml文件,文件如下:

<translate       

xmlns:android="http://schemas.android.com/apk/res/android"     

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

android:fromYDelta="-100%"       

android:toYDelta="0"     

android:duration="500" /> 

 

fromYDelta="-100%"指从-100%的位置下落到toYDelta="0"初使位置,duration指渐变时间

 

3:ScaleAnimation:在res/anim/下新建scale_animation.xml文件,文件如下:

 

fromXScale=1且toXScale=1表是从1变到1也就是X方向不变,Y从fromYScale=0.1变到toYScale=1,中心点为pivotX=50%,pivotY=50%,开始动画的时间为startOffset=100,渐变时间为duration=500

 

4:ROtateAnimation:在res/anim/下新建rotate_animation.xml文件,文件如下:

<rotate       

xmlns:android="http://schemas.android.com/apk/res/android"     

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

android:fromDegrees="0.0"     

android:toDegrees="360"     

android:pivotX="50%"     

android:pivotY="50%"     

android:duration="500" />

 

从0度变到360度,中心坐标为中心,渐变时间为500

<scale       

xmlns:android="http://schemas.android.com/apk/res/android"     

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

android:fromXScale="1"     

android:toXScale="1"     

android:fromYScale="0.1"     

android:toYScale="1.0"     

android:duration="500"     

android:pivotX="50%"     

android:pivotY="50%"     

android:startOffset="100" /> 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值