Android之Animations的使用
来源:互联网 发布:淘宝官方活动 编辑:程序博客网 时间:2024/05/21 07:31
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();
- Android之Animations的使用
- Android之各种Animations的使用总结
- Android animations的使用
- android开发之Animations的使用(一)
- android开发之Animations的使用(二)
- android开发之Animations的使用(三)
- android开发之Animations的使用(四)
- Android-Animations的使用大全之一:Tweened Animations详解
- Android Animations之LayoutAnimationController的使用方法
- Android Animations之LayoutAnimationController的使用方法
- Android 中Animations的使用 xml篇
- Android 中Animations的使用 代码篇
- android之Animations(动画)
- Android之 Animations动画
- Android Animations动画使用
- Android-Animations的使用大全之二:Frame Animation和其他
- Animations的使用(三)
- Animations的使用总结
- 变量声明提前和函数声明提前
- Android Activity 的四种启动模式 lunchMode 和 Intent.setFlags();
- 004_Http之response响应头-03禁用浏览器缓存
- 机器学习 知识图谱
- C# 中的委托和事件
- Android之Animations的使用
- JavaScript 头像上传插件源码
- Android中的android:layout_width和android:width
- IT行业专业术语
- SSM框架——实现分页和搜索分页
- 线性表
- 【深入Java虚拟机】之二:Class类文件结构
- 开启博客之旅
- CC2541读取电池电量并且广播出去