Android动画效果
来源:互联网 发布:九天封神神甲进阶数据 编辑:程序博客网 时间:2024/04/29 04:17
动画类型
android的animation由四种类型组成
XML中:alpha:渐变透明度动画效果
scale:渐变尺度伸缩动画效果
translate:画面转换位置移动动画效果
rotate:画面转移旋转动画效果
JavaCode中:AlphaAnimation:渐变透明度动画效果
ScaleAnimation:渐变尺寸伸缩动画效果
TranslateAnimation:画面转换位置移动动画效果
RotateAnimation:画面转移旋转动画效果
Android动画模式
Animation主要有两种动画模式:
一种是tweened animation(渐变动画)
JavaCode
alpha
AlphaAnimation
scale
ScaleAnimation
一种是frame by frame(画面转换动画)
XML中
JavaCode
translate
TranslateAnimation
rotate
RotateAnimation
Android的动画效果分为两种,一种是tweened animation(补间动画),第二种是frame by frame animation。一般我们用的是第一种。补间动画又分为AlphaAnimation,透明度转换 RotateAnimation,旋转转换 ScaleAnimation,缩放转换 TranslateAnimation 位置转换(移动)。
动画效果在anim目录下的xml文件中定义,在程序中用AnimationUtils.loadAnimation(Context context,int ResourcesId)载入成Animation对象,在需要显示动画效果时,执行需要动画的View的startAnimation方法,传入Animation,即可。切换Activity也可以应用动画效果,在startActivity方法后,执行overridePendingTransition方法,两个参数分别是切换前的动画效果,切换后的动画效果,下面的例子中传入的是两个alpha动画,以实现切换Activity时淡出淡入,渐隐渐现效果。
下面贴出代码:
两个Activity的布局文件 main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/ll2" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Activity2" /> <Button android:id="@+id/bt2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="返回main" /> </LinearLayout>
动画效果XML文件,全部存放在anim目录下:
a1.xml 淡出效果
java代码:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" /> </set> <!-- fromAlpha:开始时透明度 toAlpha:结束时透明度 duration:动画持续时间 -->
rotate.xml 旋转效果:
java代码:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="300" android:toDegrees="-360" android:pivotX="10%" android:pivotY="100%" android:duration="10000" /> </set> <!-- fromDegrees开始时的角度 toDegrees动画结束时角度 pivotX,pivotY不太清楚,看效果应该是定义旋转的圆心的 -->
- Android动画---Animation动画效果
- Android 动画效果 --Animation 动画
- Android 动画效果 --Animation 动画
- Android 动画效果 --Animation 动画
- Android 动画效果 --Animation 动画
- Android 动画效果 --Animation 动画
- Android 动画效果 --Animation 动画
- android 动画效果
- Android 动画效果 --Animation
- Android 动画效果 --Animation
- Android动画效果
- Android 动画效果
- android动画效果
- Android 动画效果 --Animation
- Android Animation动画效果
- android基础--动画效果
- android Animation 动画效果
- android PopupWindow 动画效果
- 神一般的debug
- 龙头股
- Android学习-应用程序管理
- ssh(struts2.3.8+spring3.2+heibernate4.1+annotation零配置
- COM, CLR, WPF, WinRT 为什么整这么多些个
- Android动画效果
- 使用Eclipse中提供的Refactor(重构)工具
- android error
- hdu 1019
- 详解Eclipse之重构(Refactor)
- iOS学习笔记(十六)——数据库操作(使用FMDB)
- 解决Linux5在telnet时报错“Unencrypted connection refused. Goodbye.”
- SoYoung的YII学习笔记3
- [探讨java深入的不变模式] java中String类的用法