打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
android动画简介

android中动画分为3种:

  1. Tween Animation:通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果,即是一种渐变动画;
  2. Frame Animation:顺序播放事先做好的图像,是一种画面转换动画。
  3. Property Animation:属性动画,通过动态地改变对象的属性从而达到动画效果,属性动画为API 11新特性。

下面只介绍前两种动画的使用方法,属性动画将在后续文章中介绍

一 Tween Animation

 Tween Animation有四种形式:

  l  alpha              渐变透明度动画效果

  l  scale              渐变尺寸伸缩动画效果

  l  translate         画面位置移动动画效果

  l  rotate              画面旋转动画效果

        这四种动画实现方式都是通过Animation类和AnimationUtils配合实现。

可以通过xml实现:动画的XML文件在工程中res/anim目录。

例如:rotate.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:fillAfter = "false"  
  5.     android:zAdjustment="bottom"  
  6.     >  
  7.     <rotate  
  8.         android:fromDegrees="0"  
  9.         android:toDegrees="360"  
  10.         android:pivotX="50%"  
  11.         android:pivotY="50%"  
  12.         android:duration="4000"  
  13.         />  
  14. </set>  

使用动画

  1. Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.rotate);  
  2.   
  3. //监听动画的状态(开始,结束)  
  4. anim.setAnimationListener(new EffectAnimationListener());  
  5. textWidget = (TextView)findViewById(R.id.text_widget);  
  6. textWidget.setText("画面旋转动画效果");  
  7. textWidget.startAnimation(anim);  

二 Frame Animation

  Frame Animation是顺序播放事先做好的图像,跟电影类似。不同于animation package,Android SDK提供了另外一个类AnimationDrawable来定义使用Frame Animation。

利用xml文件实现:res/drawable-hdpi/frame.xml:
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <animation-list  
  4.   xmlns:android="http://schemas.android.com/apk/res/android"  
  5.   android:oneshot="true"  
  6.   >  
  7.        <item android:drawable="@drawable/p1" android:duration="1000"></item>  
  8.        <item android:drawable="@drawable/p2" android:duration="1000"></item>  
  9.        <item android:drawable="@drawable/p3" android:duration="1000"></item>  
  10.        <item android:drawable="@drawable/p4" android:duration="1000"></item>  
  11.        <item android:drawable="@drawable/p5" android:duration="1000"></item>  
  12.        <item android:drawable="@drawable/p6" android:duration="1000"></item>  
  13. </animation-list>  
使用动画

  1. AnimationDrawable anim = (AnimationDrawable)getResources().  
  2. getDrawable(R.drawable.frame);  
  3. textWidget = (TextView)findViewById(R.id.text_widget);  
  4. textWidget.setText("背景渐变动画效果");  
  5. textWidget.setBackgroundDrawable(anim);  
  6. anim.start();  

这里有点不同的是,利用AnimationDrawable实现动画时,本身并没有提供接口来监听动画的状态(开始,结束),需要自己处理。


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android 动画使用心得 - 软酷快讯
Android画图学习总结
android animation
Android动画及图片的缩放和旋转
用ImageReady制作跳动的文字 - 转载教程区 - 思缘论坛 平面设计,Photos...
Android 动画之View动画效果和Activity切换动画效果
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服