Android动画编程指南

动画类型 Android的 animation 由四种类型组成 XML 中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动画效果 Java Code中 AlphaAnimation 渐变透明度动画效果 ScaleAnimation 渐变尺寸伸缩动画效果 TranslateAnimation 画面转换位置移动动画效果 RotateAnimation 画面转移旋转动画效果 Android动画模式 Animation主要有两种动画模式: 一种是tweened animation( 渐变动画 ) XML中 JavaCode alpha AlphaAnimation scale ScaleAnimation 一种是frame by frame( 画面转换动画 ) XML中 JavaCode translate TranslateAnimation rotate RotateAnimation 如何在XML 文件 中定义 动画 ①  打开Eclipse ,新建 Android 工程 ②  在res 目录中新建 anim 文件夹 ③  在anim 目录中新建一个 myanim.xml( 注意文件名小写 ) ④  加入XML 的动画代码 1.

2. 3. 4. 5. 6. 7. 复制代码 Android动画解析 --XML 1.

2. 3. 8.

22. 复制代码 1.

2. 3. 14. 15.

复制代码 1.

2. 3. 10.

23. 复制代码 1.

2. 3. 10.

42. 复制代码 如何使用XML 中的动画效果 1.public static Animation loadAnimation (Context context, int id) 2.//第一个参数Context为程序 的上下文 3.//第二个参数id为动画XML文件的引用 4.//例子 : 5.myAnimation= AnimationUtils.loadAnimation(this,R.anim.my_action); 6.//使用AnimationUtils类的静态方法loadAnimation()来加载XML中的动画XML文件复制代码 如何在Java 代码中定义动画 1.//在代码中定义 动画实例 对象 2.private Animation myAnimation_Alpha; 3.private Animation myAnimation_Scale; 4.private Animation myAnimation_Translate; 5.private Animation myAnimation_Rotate; 6. 7. //根据各自的构造方法来初始化一个实例对象 8.myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f); 9. 10.myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, 11. Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 12. 13.myAnimation_Translate=new TranslateAnimation(30.0f, -80.0f, 30.0f, 300.0f); 14. 15.myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f, 16. Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f); 复制代码 Android动画解析 --JavaCode AlphaAnimation ① AlphaAnimation类对象定义 1.private AlphaAnimation myAnimation_Alpha; 复制代码 ② AlphaAnimation类对象构造 1.AlphaAnimation(float fromAlpha, float toAlpha) 2.//第一个参数fromAlpha为 动画开始时候透明度 3.//第二个参数toAlpha为 动画结束时候透明度 4.myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f); 5.//说明: 6.// 0.0表示完全透明 7.// 1.0表示完全不透明复制代码 ③ 设置动画持续时间 1.myAnimation_Alpha.setDuration(5000); 2.//设置时间持续时间为 5000毫秒复制代码 ScaleAnimation ① ScaleAnimation类对象定义 1.private AlphaAnimation myAnimation_Alpha; 复制代码 ② ScaleAnimation类对象构造 1.ScaleAnimation(float fromX, float toX, float fromY, float toY, 2. int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) 3.//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸 4.//第二个参数toX为动画结束时 X坐标上的伸缩尺寸 5.//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸 6.//第四个参数toY为动画结束时Y坐标上的伸缩尺寸 7./*说明: 8. 以上四种属性值 9. 0.0表示收缩到没有 10. 1.0表示正常无伸缩 11. 值小于1.0表示收缩 12. 值大于1.0表示放大 13.*/ 14.//第五个参数pivotXType为动画在X轴相对于物件位置类型 15.//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置 16.//第七个参数pivotXType为动画在Y轴相对于物件位置类型 17.//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置 18.myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, 19. Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 复制代码 ③ 设置动画持续时间 1.myAnimation_Scale.setDuration(700); 2.//设置时间持续时间为 700毫秒复制代码 TranslateAnimation ① TranslateAnimation类对象定义 1.private AlphaAnimation myAnimation_Alpha; 复制代码 ② TranslateAnimation类对象构造 1.TranslateAnimation(float fromXDelta, float toXDelta, 2. float fromYDelta, float toYDelta) 3.//第一个参数fromXDelta为动画起始时 X坐标上的移动位置 4.//第二个参数toXDelta为动画结束时 X坐标上的移动位置 5.//第三个参数fromYDelta为动画起始时Y坐标上的移动位置 6.//第四个参数toYDelta为动画结束时Y坐标上的移动位置复制代码 ③ 设置动画持续时间 1.myAnimation_Translate.setDuration(2000); 2.//设置时间持续时间为 2000毫秒复制代码 RotateAnimation ①  RotateAnimation类对象定义 1.private AlphaAnimation myAnimation_Alpha; 复制代码 ②  RotateAnimation类对象构造 1.RotateAnimation(float fromDegrees, float toDegrees, 2. int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) 3.//第一个参数fromDegrees为动画起始时的旋转角度 4.//第二个参数toDegrees为动画旋转到的角度 5.//第三个参数pivotXType为动画在X轴相对于物件位置类型 6.//第四个参数pivotXValue为动画相对于物件的X坐标的开始位置 7.//第五个参数pivotXType为动画在Y轴相对于物件位置类型 8.//第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置 9.myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f, 10. Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f); 复制代码 ③  设置动画持续时间 1.myAnimation_Rotate.setDuration(3000); 2.//设置时间持续时间为 3000毫秒 复制代码 如何使用 Java 代码中的动画效果 使用从 View 父类继承过来的方法 startAnimation ()来为 View 或是子类 View 等等添加一个动画效果 1.public void startAnimation (Animation animation)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值