android动画简介
来源:互联网 发布:上海医疗网络总监招聘 编辑:程序博客网 时间:2024/06/14 23:21
android动画分为3种:
Tween Anination: 渐变动画,通过图像变换(平移、缩放、旋转)的动画。
Frame Animation:通过顺序播放图片达到一种画面切换。
Property Animation :属性动画,通过动态地改变对象属性来达到动画效果。
本文先讲解Tween 和 Frame动画,属性动画将在后续进行讲解
Tween动画包含以下四种:alpha 渐变动画;scale 缩放动画;translate 位移转换动画;rotate 旋转动画。
以上四种动画都是通过Animation来实现,可以通过XML和Java语言两种方式进行实现,下面将进行详细说明:
(1)alpha animation
xml方式:在res/anim文件夹下建立alpha_anim.xml文件
<?xml version="1.0"encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1"
android:toAlpha="0" >
</alpha>
在需要进行动画的地方使用如下方式进行调用:
Animation alphaAnimation =AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha_anim);
alphaAnimation.setDuration(1000);
alphaAnimation.setFillAfter(true);
view.startAnimation(alphaAnimation);
该代码会实现view从不透明到100%透明
java方式(实现结果与XML一致):
Animation alphaAnimation = new AlphaAnimation(1f, 0f);
alphaAnimation.setDuration(1000);
alphaAnimation.setFillAfter(true);
v.startAnimation(alphaAnimation);
(2)scale animation
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:toXScale="2"
android:fromYScale="1"
android:toYScale="2">
</scale>
该XML会使view从本身大小扩大到2倍大小
(3)translateanimation
<?xml version="1.0"encoding="utf-8"?>
<translatexmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%"
android:toXDelta="0"
android:fromYDelta="-100%"
android:toYDelta="0">
</translate>
这将会实现View从屏幕外移动到屏幕中,已左上角坐标为标准
(4)rotateanimation
<?xml version="1.0" encoding="utf-8"?>
<rotatexmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
将会实现view旋转一周,已view的中心为圆心
Frame动画,frame动画播放事先按照顺序配置好的图片,使用方式如下:
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true" >
<item android:drawable="@drawable/ic_launcher"android:duration="1000"></item>
<item android:drawable="@drawable/image_1"android:duration="1000"></item>
<item android:drawable="@drawable/image_2"android:duration="1000"></item>
<item android:drawable="@drawable/image_3"android:duration="1000"></item>
<item android:drawable="@drawable/image_4"android:duration="1000"></item>
<item android:drawable="@drawable/ic_launcher"android:duration="1000"></item>
</animation-list>
与Tween不同的是,frame_anim.xml需要放到drawable文件夹下,并使用AnimationDrawable。
AnimationDrawableanim = (AnimationDrawable)getResources(). getDrawable(R.drawable.frame_anim);
mImageView.setBackgroundDrawable(anim);
anim.start();
- 动画一 android动画简介
- android 动画效果 简介
- android动画简介
- android动画简介
- Android 属性动画简介
- Android 属性动画简介
- android 动画interpolator简介
- android动画简介
- Android 动画-简介
- Android动画使用简介
- Android动画之旅-开篇动画简介
- Android 帧动画使用简介
- Android页面跳转动画简介
- Android 三大动画简介
- android切换动画overridePendingTransition的简介
- Android学习笔记之动画简介
- android 动画学习1(简介与视图动画)
- Android动画学习(一)——Android动画系统框架简介
- vi使用总结
- 中国经济走出困局的最后选择--刘胜军
- 深入理解java虚拟机
- 555555555555555
- CWinAppEx::InitContextMenuManager
- android动画简介
- ucenter与其它应用结合时出现通信失败
- 安装VirtualBox时系统找不到指定路径的解决方法
- Android Studio环境搭建
- Leetcode NO.70 Climbing Stairs
- 并发编程7 - 任务取消
- 项目风险管理
- JAVASCRIPT中的数字,注意点
- CWinAppEx::InitKeyboardManager