Android之Animations的使用
2016-02-27 15:52
363 查看
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
使用Tweened Animations的第二种使用步骤:
1. 在res文件夹下面新建一个名为anim的文件夹
2. 创建xml文件,并首先加入set标签,改标签如下:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
//interpolator定义动画变化的速率
</set>
3. 在该标签当中加入rotate,alpha,scale或者translate标签,例子如下:
<alpha
android:fromAlpha = "0.1"
android:toAlpha = "1.0"
android:duration = "3000"/>
<rotate
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"/>
---注意---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文件,用于定义Animations的动画序列,以下是例子:
<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("在res/drawable当中创建一个xml文件的Id");
3. AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();
4. animationDrawable.start();
使用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
使用Tweened Animations的第二种使用步骤:
1. 在res文件夹下面新建一个名为anim的文件夹
2. 创建xml文件,并首先加入set标签,改标签如下:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
//interpolator定义动画变化的速率
</set>
3. 在该标签当中加入rotate,alpha,scale或者translate标签,例子如下:
<alpha
android:fromAlpha = "0.1"
android:toAlpha = "1.0"
android:duration = "3000"/>
<rotate
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"/>
---注意---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文件,用于定义Animations的动画序列,以下是例子:
<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("在res/drawable当中创建一个xml文件的Id");
3. AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();
4. animationDrawable.start();
相关文章推荐
- Android即时通讯--仿QQ即时聊天:(五)聊天模块
- Android Activity 的四种启动模式 lunchMode 和 Intent.setFlags();
- android meta-data的使用以及含义
- android 【九种对话框】的实现方式
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
- PDF阅读器系列之--MuPDF源码分析过程(二)
- Android高手进阶:Adapter深入理解与优化
- Android Binder机制(超级详尽)
- android 仿nice实现在图片上打标签
- Android Fragment 生命周期图
- 学习android service记录
- Android数据通信——JSON&Gson(Android studio)
- Android View 事件体系1
- H5为主的Hybrid App技术方案的设想及设计-Android
- Android Studio 9 patch 编译错误
- android、IOS和手机基础知识
- Android_为什么要继承onMeasure()
- android 性能优化-电量篇
- BUG记录之Android开发
- android的 root权限