android开发动画入门教程.docx_第1页
android开发动画入门教程.docx_第2页
android开发动画入门教程.docx_第3页
android开发动画入门教程.docx_第4页
android开发动画入门教程.docx_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Android动画效果入门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中JavaCodealphaAlphaAnimationscaleScaleAnimation一种是frame by frame(画面转换动画)XML中JavaCodetranslateTranslateAnimationrotateRotateAnimation如何在XML文件中定义动画:打开Eclipse,新建Android工程在res目录中新建anim文件夹在anim目录中新建一个myanim.xml(注意文件名小写)加入XML的动画代码复制代码Android动画解析-XML复制代码复制代码复制代码复制代码如何使用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动画解析-JavaCodeAlphaAnimationAlphaAnimation类对象定义private AlphaAnimation myAnimation_Alpha;复制代码AlphaAnimation类对象构造AlphaAnimation(float fromAlpha, float toAlpha)/第一个参数fromAlpha为 动画开始时候透明度/第二个参数toAlpha为 动画结束时候透明度myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f);/说明:/ 0.0表示完全透明/ 1.0表示完全不透明复制代码设置动画持续时间myAnimation_Alpha.setDuration(5000);/设置时间持续时间为 5000毫秒复制代码ScaleAnimationScaleAnimation类对象定义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毫秒复制代码TranslateAnimationTranslateAnimation类对象定义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毫秒复制代码RotateAnimationRotateAnimation类对象定义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毫秒复制

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论