Animation的使用

转自:http://www.cnblogs.com/lee0oo0/archive/2012/05/22/2513008.html

一、Animations一般分为两大类,一类是补间动画(Tweened):如淡入淡出,旋转,缩放,移动;另一类是帧动画Frame-by-Frame,就如电影一般由多张图片按照一定的时间间隔显示。

二、Tweened Animations的使用(两种方式

第一种:

1. 创建一个AnimationSet对象,AnimationSet animationSet = new AnimationSet (boolean b);   //b为true表示共享Interpolator

2. 根据需要创建相应的Animation对象(AlphaAnimation、RotateAnimation、ScaleAnimation、TranslateAnimation)

3. 根据软件动画的需求,为Animation对象设置相应的数据

4. 将Animation对象添加到AnimationSet对象当中,使用addAnimation方法

5. 使用控件对象开始执行AnimationSet

注意:alpha取值 0-1.0,表示的意思为不透明度,0是全透明状态,1是完全不透明状态

第二种:

1.  在res文件夹下面新建一个名为anim的文件夹.

2. 创建xml文件,并首先加入set标签,标签如下:

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

</set>

3. 在set标签中加入rotate,alpha,scale或者translate标签,例子如下:

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

    <alpha
        android:duration="3000"
        android:fromAlpha="0.1"
        android:toAlpha="1.0" />
    <rotate
        android:duration="3000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="+350" />
</set>

注意:  android:pivotX的值共有三种设置方法:

1)android:pivotX="50"这种方法使用绝对位置定位

2)android:pivotX="50%"这种方法相对于控件本身定位

3)android:pivotX="50%p"这种方法相对于控件的父控件定位 

4. 在代码当中使用AnimationUtils当中装载xml文件,并生成Animation对象,AnimationUtils.loadAnimation

三、Frame-By-Frame(帧动画)使用方法

1. 在res/drawable当中创建一个xml文件(animation_list.xml)

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item
        android:drawable="drawable/nv1"
        android:duration="500" />
    <item
        android:drawable="drawable/nv2"
        android:duration="500" />
    <item
        android:drawable="drawable/nv3"
        android:duration="500" />
    <item
        android:drawable="drawable/nv4"
        android:duration="500" />
</animation-list> 

2.

        imageView. setBackgroundResource(R.drawable.animation_list);

3. 

        AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();

4. 

        animationDrawable.start();

注意: animation-list标签中的  android:oneshot="false"  false表示图片一直循环播放,true表示只循环一遍
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值