您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 企业财务 > android动画学习笔记及源码
RexseeAPI介绍:Animations动画学习笔记及源码在Android上实现动画,官方的SDK提供了Animations,并且介绍了两种不同模式,分别是:1.TweenAnimation:通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果,即是一种渐变动画;2.FrameAnimation:顺序播放事先做好的图像,是一种画面转换动画。同时,Animation由四种类型组成:XML文件:·alpha渐变透明度动画效果·scale渐变尺寸伸缩动画效果·translate画面转换位置移动动画效果·rotate画面转移旋转动画效果在Java源码中定义了相应的类,可以使用这些类的方法来获取和操作相应的属性:·AlphaAnimation渐变透明度动画效果·ScaleAnimation渐变尺寸伸缩动画效果·TranslateAnimation画面转换位置移动动画效果·RotateAnimation画面转移旋转动画效果具体Android的原生就不再多说了,相对复杂,有兴趣的可以直接去看google的SDK。这里分享了Rexsee的API,基于对原生的封装,可以直接使用JS实现功能调用。如:【事件】voidonAnimationStart(Stringid)【说明】当动画开始播放时触发。在Rexsee社区可以直接查看源码。同时,新上线的项目中心提供了在线开发服务,不需要单独准备服务器。同时也有大量的应用以分享的方式开放供查阅,关于动画的具体应用源码也可以在这里查到::Animations源码Java代码packagerexsee.core.animation;importrexsee.core.style.StyleSheet;importrexsee.core.utilities.RexseeUtilities;importandroid.view.View;importandroid.view.animation.AccelerateDecelerateInterpolator;importandroid.view.animation.AccelerateInterpolator;importandroid.view.animation.AlphaAnimation;importandroid.view.animation.Animation;importandroid.view.animation.AnimationSet;importandroid.view.animation.AnticipateInterpolator;importandroid.view.animation.AnticipateOvershootInterpolator;importandroid.view.animation.BounceInterpolator;importandroid.view.animation.CycleInterpolator;importandroid.view.animation.DecelerateInterpolator;importandroid.view.animation.Interpolator;importandroid.view.animation.LinearInterpolator;importandroid.view.animation.OvershootInterpolator;importandroid.view.animation.RotateAnimation;importandroid.view.animation.ScaleAnimation;importandroid.view.animation.TranslateAnimation;publicclassAnimationsextendsAnimation{publicAnimations(){super();}publicstaticAnimationgetAnimation(StyleSheetstyle,AnimationListenerlistener,Viewview,ViewviewParent){if(view==null)returnnull;if(viewParent==null){try{viewParent=(View)view.getParent();}catch(Exceptione){viewParent=view;}}AnimationSetanimation=newAnimationSet(true);String[]types=style.animation_type.split(\\+);intlength=0;animation.setDuration(Integer.parseInt(style.animation_rotate_duration));animation.setRepeatCount(Integer.parseInt(style.animation_rotate_repeat_count));animation.setRepeatMode(style.animation_rotate_repeat_mode.equalsIgnoreCase(normal)?1:2);animation.setStartOffset(RexseeUtilities.getLong(style.animation_rotate_start_time,0));animation.setInterpolator(getInterPolator(style.animation_rotate_interpolator));animation.initialize(view.getWidth(),view.getHeight(),viewParent.getWidth(),viewParent.getHeight());}catch(Exceptione){}returnanimation;}publicstaticAnimationgetAlphaAnimation(StyleSheetstyle,Viewview,ViewviewParent){Animationanimation=null;try{floatfrom=Float.parseFloat(style.animation_alpha_from.replaceAll(%,))/100;floatto=Float.parseFloat(style.animation_alpha_to.replaceAll(%,))/100;animation=newAlphaAnimation(from,to);animation.setDuration(Integer.parseInt(style.animation_alpha_duration));animation.setRepeatCount(Integer.parseInt(style.animation_alpha_repeat_count));animation.setRepeatMode(style.animation_alpha_repeat_mode.equalsIgnoreCase(normal)?1:2);animation.setStartOffset(RexseeUtilities.getLong(style.animation_alpha_start_time,0));animation.setInterpolator(getInterPolator(style.animation_alpha_interpolator));animation.initialize(view.getWidth(),view.getHeight(),viewParent.getWidth(),viewParent.getHeight());}catch(Exceptione){}returnanimation;}publicstaticAnimationgetScaleAnimation(StyleSheetstyle,Viewview,ViewviewParent){Animationanimation=null;try{floatscaleCenterX,scaleCenterY;try{scaleCenterX=Float.parseFloat(style.animation_scale_center_x.replaceAll(%,));scaleCenterX=scaleCenterX/100;if(scaleCenterX0)scaleCenterX=0;if(scaleCenterX1)scaleCenterX=1;}catch(Exceptione){scaleCenterX=(float)0.5;}try{scaleCenterY=Float.parseFloat(style.animation_scale_center_y.replaceAll(%,));scaleCenterY=scaleCenterY/100;if(scaleCenterY0)scaleCenterY=0;if(scaleCenterY1)scaleCenterY=1;}catch(Exceptione){scaleCenterY=(float)0.5;}floatfromX=Float.parseFloat(style.animation_scale_x_from);floattoX=Float.parseFloat(style.animation_scale_x_to);floatfromY=Float.parseFloat(style.animation_scale_y_from);floattoY=Float.parseFloat(style.animation_scale_y_to);animation=newScaleAnimation(fromX,toX,fromY,toY,Animation.RELATIVE_TO_PARENT,scaleCenterX,Animation.RELATIVE_TO_PARENT,scaleCenterY);animation.setDuration(Integer.parseInt(style.animation_scale_duration));animation.setRepeatCount(Integer.parseInt(style.animation_scale_repeat_count));animation.setRepeatMode(style.animation_scale_repeat_mode.equalsIgnoreCase(normal)?1:2);animation.setStartOffset(RexseeUtilities.getLong(style.animation_scale_start_time,0));animation.setInterpolator(getInterPolator(style.animation_scale_interpolator));animation.initialize(view.getWidth(),view.getHeight(),viewParent.getWidth(),viewParent.getHeig
本文标题:android动画学习笔记及源码
链接地址:https://www.777doc.com/doc-3985049 .html