AndroidViewAnimations开源框架实现
来源:互联网 发布:上证综合指数数据 编辑:程序博客网 时间:2024/05/18 03:40
1.这是一个开源的动画库,首先感谢作者的分享。
BaseViewAnimator.class
这个是所有动画对象的基类,主要用来设置动画的属性。
public abstract class BaseViewAnimator {public static final long DURATION = 1000;private AnimatorSet mAnimatorSet;// 存放动画对象的集合private long mDuration = DURATION;// 默认的持续时间{mAnimatorSet = new AnimatorSet();}/** * 子类中需要实现的方法 * * @param target */protected abstract void prepare(View target);/** * 设置目标view * * @param target * @return */public BaseViewAnimator setTarget(View target) {reset(target);prepare(target);return this;}/** * 开始动画 */public void animate() {start();}/** * 开始动画 */public void start() {mAnimatorSet.setDuration(mDuration);mAnimatorSet.start();}/** * 重置view上面的状态 * * @param target */public void reset(View target) {ViewHelper.setAlpha(target, 1);ViewHelper.setScaleX(target, 1);ViewHelper.setScaleY(target, 1);ViewHelper.setTranslationX(target, 0);ViewHelper.setTranslationY(target, 0);ViewHelper.setRotation(target, 0);ViewHelper.setRotationY(target, 0);ViewHelper.setRotationX(target, 0);ViewHelper.setPivotX(target, target.getMeasuredWidth() / 2.0f);ViewHelper.setPivotY(target, target.getMeasuredHeight() / 2.0f);}/** * 设置延续时间 * * @param duration * @return */public BaseViewAnimator setDuration(long duration) {mDuration = duration;return this;}/** * 设置开始的延迟时间 * * @param delay * @return */public BaseViewAnimator setStartDelay(long delay) {getAnimatorAgent().setStartDelay(delay);return this;}public long getStartDelay() {return mAnimatorSet.getStartDelay();}/** * 添加监听器 * * @param l * @return */public BaseViewAnimator addAnimatorListener(AnimatorListener l) {mAnimatorSet.addListener(l);return this;}public void cancel() {mAnimatorSet.cancel();}public boolean isRunning() {return mAnimatorSet.isRunning();}public boolean isStarted() {return mAnimatorSet.isStarted();}public void removeAnimatorListener(AnimatorListener l) {mAnimatorSet.removeListener(l);}public void removeAllListener() {mAnimatorSet.removeAllListeners();}/** * 设置间插器 * * @param interpolator * @return */public BaseViewAnimator setInterpolator(Interpolator interpolator) {mAnimatorSet.setInterpolator(interpolator);return this;}public long getDuration() {return mDuration;}/** * 获得动画对象存放的集合 * * @return */public AnimatorSet getAnimatorAgent() {return mAnimatorSet;}}
Techniques.class
这个类是个枚举类,枚举出了所有实现了得对话对象:
public enum Techniques { DropOut(DropOutAnimator.class), Landing(LandingAnimator.class), TakingOff(TakingOffAnimator.class), Flash(FlashAnimator.class), Pulse(PulseAnimator.class), RubberBand(RubberBandAnimator.class), Shake(ShakeAnimator.class), Swing(SwingAnimator.class), Wobble(WobbleAnimator.class), Bounce(BounceAnimator.class), Tada(TadaAnimator.class), StandUp(StandUpAnimator.class), Wave(WaveAnimator.class), Hinge(HingeAnimator.class), RollIn(RollInAnimator.class), RollOut(RollOutAnimator.class), BounceIn(BounceInAnimator.class), BounceInDown(BounceInDownAnimator.class), BounceInLeft(BounceInLeftAnimator.class), BounceInRight(BounceInRightAnimator.class), BounceInUp(BounceInUpAnimator.class), FadeIn(FadeInAnimator.class), FadeInUp(FadeInUpAnimator.class), FadeInDown(FadeInDownAnimator.class), FadeInLeft(FadeInLeftAnimator.class), FadeInRight(FadeInRightAnimator.class), FadeOut(FadeOutAnimator.class), FadeOutDown(FadeOutDownAnimator.class), FadeOutLeft(FadeOutLeftAnimator.class), FadeOutRight(FadeOutRightAnimator.class), FadeOutUp(FadeOutUpAnimator.class), FlipInX(FlipInXAnimator.class), FlipOutX(FlipOutXAnimator.class), FlipOutY(FlipOutYAnimator.class), RotateIn(RotateInAnimator.class), RotateInDownLeft(RotateInDownLeftAnimator.class), RotateInDownRight(RotateInDownRightAnimator.class), RotateInUpLeft(RotateInUpLeftAnimator.class), RotateInUpRight(RotateInUpRightAnimator.class), RotateOut(RotateOutAnimator.class), RotateOutDownLeft(RotateOutDownLeftAnimator.class), RotateOutDownRight(RotateOutDownRightAnimator.class), RotateOutUpLeft(RotateOutUpLeftAnimator.class), RotateOutUpRight(RotateOutUpRightAnimator.class), SlideInLeft(SlideInLeftAnimator.class), SlideInRight(SlideInRightAnimator.class), SlideInUp(SlideInUpAnimator.class), SlideInDown(SlideInDownAnimator.class), SlideOutLeft(SlideOutLeftAnimator.class), SlideOutRight(SlideOutRightAnimator.class), SlideOutUp(SlideOutUpAnimator.class), SlideOutDown(SlideOutDownAnimator.class), ZoomIn(ZoomInAnimator.class), ZoomInDown(ZoomInDownAnimator.class), ZoomInLeft(ZoomInLeftAnimator.class), ZoomInRight(ZoomInRightAnimator.class), ZoomInUp(ZoomInUpAnimator.class), ZoomOut(ZoomOutAnimator.class), ZoomOutDown(ZoomOutDownAnimator.class), ZoomOutLeft(ZoomOutLeftAnimator.class), ZoomOutRight(ZoomOutRightAnimator.class), ZoomOutUp(ZoomOutUpAnimator.class); private Class animatorClazz; private Techniques(Class clazz) { animatorClazz = clazz; } public BaseViewAnimator getAnimator() { try { return (BaseViewAnimator) animatorClazz.newInstance(); } catch (Exception e) { throw new Error("Can not init animatorClazz instance"); } }}
YoYo.class
这个类采用了链式api的方式:
通过静态方法将动画对象传入:
public static AnimationComposer with(Techniques techniques) { return new AnimationComposer(techniques); } public static AnimationComposer with(BaseViewAnimator animator) { return new AnimationComposer(animator); }内部类 AnimationComposer.class就相当于一个builder构造器,用来设置各种属性:
public static final class AnimationComposer { private List<Animator.AnimatorListener> callbacks = new ArrayList<Animator.AnimatorListener>(); private BaseViewAnimator animator; private long duration = DURATION; private long delay = NO_DELAY; private Interpolator interpolator; private View target; private AnimationComposer(Techniques techniques) { this.animator = techniques.getAnimator(); } private AnimationComposer(BaseViewAnimator animator) { this.animator = animator; } public AnimationComposer duration(long duration) { this.duration = duration; return this; } public AnimationComposer delay(long delay) { this.delay = delay; return this; } public AnimationComposer interpolate(Interpolator interpolator) { this.interpolator = interpolator; return this; } public AnimationComposer withListener(Animator.AnimatorListener listener) { callbacks.add(listener); return this; } public YoYoString playOn(View target) { this.target = target; return new YoYoString(new YoYo(this).play(), this.target); } }通过一系列方法设置一系列参数,最后调用
playOn(View target)
public YoYoString playOn(View target) { this.target = target; return new YoYoString(new YoYo(this).play(), this.target); }来开启动画,实际上最后还是调用了new YoYo(this).play()来开启动画:
private BaseViewAnimator play() { animator.setTarget(target); animator.setDuration(duration) .setInterpolator(interpolator) .setStartDelay(delay); if (callbacks.size() > 0) { for (Animator.AnimatorListener callback : callbacks) { animator.addAnimatorListener(callback); } } animator.animate(); return animator; }
animator.animate();是调用如下方法:
/** * 开始动画 */public void animate() {start();}/** * 开始动画 */public void start() {mAnimatorSet.setDuration(mDuration);mAnimatorSet.start();}然后各种动画效果就不分析了。
0 0
- AndroidViewAnimations开源框架实现
- 【开源库大全】二、AndroidViewAnimations
- AndroidViewAnimations任何控件的动画库
- AndroidViewAnimations:Andorid视图动画合集YOYO
- 【Android开源框架】使用andbase开发框架实现绘制折线图
- 《开源框架那点事儿25》:对框架模板引擎实现方式的改造实录
- 《开源框架那点事儿25》:对框架模板引擎实现方式的改造实录
- java分布式,基于开源框架实现消息方式
- 【IOS功能实现】之:Core Plot开源框架使用
- Android开源框架ViewPageIndicator和ViewPager实现Tab导航
- 常用效果实现开源框架(没图)
- [重写开源框架源码]SwipeBackLayout实现全屏滑动
- 开源框架SDWebImage的基本实现及思想
- Android_SlidingMenu开源项目_导航框架实现侧滑
- 开源框架android-times-square实现日历选择日期
- 侧滑菜单的实现方式(二):开源框架
- Android开源框架ViewPageIndicator和ViewPager实现Tab导航
- Android中使用开源框架PagerSlidingTabStrip实现导航标题
- Code Forces 557 A. Ilya and Diplomas(水~)
- Java项目经验
- 2.朴素贝叶斯Naive Bayes
- 5年后你想过什么样的生活?
- file explorer查看手机SD卡data目录
- AndroidViewAnimations开源框架实现
- 数据库日记文件的查看与修改
- Lakes Environmental ARTM View v1.4.2 1CD放射物扩散模拟模型
- HDU - 2161 - Primes (质数)
- 解决子级用css float浮动 而父级div没高度不能自适应高度 - DIVCSS
- Tomcat 简介
- poj 2096 概率dp
- Lakes.AERMOD.View.v8.9.0 1CD大气扩散模型软件包
- Fisher线性判别函数+c代码