资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
http:/www.xaandroid.comhttp:/www.xaandroid.comAndroid 动画效果入门Android 是有谷歌在 07 年推出的一个开放系统平台,主要针对移动设备市场,目前版本为 android 4.0.android 基于 linux,开发者可以使用 java 或者 c/c+开发 android 应用。现在 android 的应用越来越广泛了,许多都是在 android 上面开发的。所以: 今天我们来讲 android 开发入门动画效果入门。动画效果编程基础-Android Animation首先我们来说说动画类型:Android 的 animation 由四种类型组成 XML 中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面旋转动画效果 JavaCode 中 AlphaAnimation 渐变透明度动画效果 ScaleAnimation 渐变尺寸伸缩动画效果 TranslateAnimation 画面转换位置移动动画效果 RotateAnimation 画面旋转动画效果 Animation 主要有两种动画模式: 一种是 tweened animation(渐变动画) XML 中 JavaCode alpha AlphaAnimation scale ScaleAnimation 一种是 frame by frame(画面转换动画) http:/www.xaandroid.comhttp:/www.xaandroid.comXML 中 JavaCode translate TranslateAnimation rotate RotateAnimation 如何在 XML 文件中定义动画 : 打开 Eclipse,新建 Android 工程 在 res 目录中新建 anim 文件夹 在 anim 目录中新建一个 myanim.xml(注意文件名小写) 加入 XML 的动画代码 复制代码 Android 动画解析-XML 复制代码 复制代码 复制代码 http:/www.xaandroid.comhttp:/www.xaandroid.comhttp:/www.xaandroid.comhttp:/www.xaandroid.com复制代码 如何使用 XML 中的动画效果 public static Animation loadAnimation (Context context, int id) /第一个参数 Context 为程序的上下文 /第二个参数 id 为动画 XML 文件的引用 /例子: myAnimation= AnimationUtils.loadAnimation(this,R.anim.my_action); /使用 AnimationUtils 类的静态方法 loadAnimation()来加载 XML 中的动画 XML 文件 复制代码 如何在 Java 代码中定义动画 /在代码中定义 动画实例对象 private Animation myAnimation_Alpha; private Animation myAnimation_Scale; private Animation myAnimation_Translate; private Animation myAnimation_Rotate; /根据各自的构造方法来初始化一个实例对象 myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f); myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); myAnimation_Translate=new TranslateAnimation(30.0f, -80.0f, 30.0f, 300.0f); myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f); 复制代码 Android 动画解析-JavaCode AlphaAnimation AlphaAnimation 类对象定义 private AlphaAnimation myAnimation_Alpha; 复制代码 AlphaAnimation 类对象构造 AlphaAnimation(float fromAlpha, float toAlpha) /第一个参数 fromAlpha 为 动画开始时候透明度 http:/www.xaandroid.comhttp:/www.xaandroid.com/第二个参数 toAlpha 为 动画结束时候透明度 myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f); /说明: / 0.0 表示完全透明 / 1.0 表示完全不透明 复制代码 设置动画持续时间 myAnimation_Alpha.setDuration(5000); /设置时间持续时间为 5000 毫秒 复制代码 ScaleAnimation ScaleAnimation 类对象定义 private AlphaAnimation myAnimation_Alpha; 复制代码 ScaleAnimation 类对象构造 ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) /第一个参数 fromX 为动画起始时 X 坐标上的伸缩尺寸 /第二个参数 toX 为动画结束时 X 坐标上的伸缩尺寸 /第三个参数 fromY 为动画起始时 Y 坐标上的伸缩尺寸 /第四个参数 toY 为动画结束时 Y 坐标上的伸缩尺寸 /*说明: 以上四种属性值 0.0 表示收缩到没有 1.0 表示正常无伸缩 值小于 1.0 表示收缩 值大于 1.0 表示放大 */ /第五个参数 pivotXType 为动画在 X 轴相对于物件位置类型 /第六个参数 pivotXValue 为动画相对于物件的 X 坐标的开始位置 /第七个参数 pivotXType 为动画在 Y 轴相对于物件位置类型 /第八个参数 pivotYValue 为动画相对于物件的 Y 坐标的开始位置 myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 复制代码 设置动画持续时间 myAnimation_Scale.setDuration(700); /设置时间持续时间为 700 毫秒 复制代码 TranslateAnimation http:/www.xaandroid.comhttp:/www.xaandroid.com TranslateAnimation 类对象定义 private AlphaAnimation myAnimation_Alpha; 复制代码 TranslateAnimation 类对象构造 TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) /第一个参数 fromXDelta 为动画起始时 X 坐标上的移动位置 /第二个参数 toXDelta 为动画结束时 X 坐标上的移动位置 /第三个参数 fromYDelta 为动画起始时 Y 坐标上的移动位置 /第四个参数 toYDelta 为动画结束时 Y 坐标上的移动位置 复制代码 设置动画持续时间 myAnimation_Translate.setDuration(2000); /设置时间持续时间为 2000 毫秒 复制代码 RotateAnimation RotateAnimation 类对象定义 private AlphaAnimation myAnimation_Alpha; 复制代码 RotateAnimation 类对象构造 RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) /第一个参数 fromDegrees 为动画起始时的旋转角度 /第二个参数 toDegrees 为动画旋转到的角度 /第三个参数 pivotXType 为动画在 X 轴相对于物件位置类型 /第四个参数 pivotXValue 为动画相对于物件的 X 坐标的开始位置 /第五个参数 pivotXType 为动画在 Y 轴相对于物件位置类型 /第六个参数 pivotYValue 为动画相对于物件的 Y 坐标的开始位置 myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f); 复制代码 设置动画持续时间 myAnimation_Rotate.setDuration(3000); /设置时间持续时间为 3000 毫秒 复制代码 如何使用 Java 代码中的动画效果 使用从 View 父类继承过来的方法 startAnimation()来为 View 或是子类 View 等等添加一个http:/www.xaandroid.comhttp:/www.xaandroid.com动画效果。以上就是 android 动画入门的一些基础内容,如果还有什么不懂的可以去网上搜一些视频 课程来看,我呢也会在以后的日子里继续的为大家写一些基础类的其他课程。希望有兴趣 的朋友可以多多指教。
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号