Android基于Facebook Rebound的动画效果框架Backboard demo (非常炫酷)
来源:互联网 发布:石油钻井数据与油价 编辑:程序博客网 时间:2024/04/30 10:34
一个基于Facebook Rebound的动效框架Backboard,封装了一些API,便于开发者更方便的把View与Motion结合起来,一些效果很棒 :https://github.com/tumblr/Backboard Demo :https://github.com/tumblr/Backboard/releases
使用说明:
Usage
更新build.gradle
dependencies {
compile
'com.facebook.rebound:rebound:0.3.8'
compile
'com.tumblr.backboard:backboard:+'
}
开始
Backboard是一个基于rebound 的框架,它管理spring的使用,简化了最常用的用例:
Actions, such as MotionEvents, are mapped to Springs via Imitators.
Springs are mapped to Views and view properties via Performers.
In addition, an Actor wraps the above objects and provides a simple interface for mapping touch motion to a view's position - dragging.
Performers
一个Performer获取Spring当前的值并把它设置为view的一个属性值。
Spring bounce = SpringSystem.create().createSpring();
Performer xMotion =
new
Performer(view, View.TRANSLATION_X);
bounce.addListener(xMotion);
对那些想节约屏幕空间的人来说,可以使用 流式接口 :
Spring bounce = SpringSystem.create().createSpring().addListener(
new
Performer(view, View.TRANSLATION_X));
Imitators
An Imitator constantly perturbs the Spring it is attached to. This perturbation can originate a variety of sources:
A MotionEvent, where the Spring can change based on the action (ACTION_DOWN,ACTION_UP), or imitate a property (x, y, etc.). These are called EventImitators.
Another Spring, which leads to results similar to springs being chained together. These are called SpringImitators.
Imitating Touch
An EventImitator primarily operates with OnTouchListeners. The simplest example is aToggleImitator, which toggles between two different values depending on the touch state:
view.setOnTouchListener(
new
ToggleImitator(spring, 0, 1));
when the user touches the view, a value of 1 is set on the spring, and when the user releases, a value of 0 is set.
Imitating Motion
A MotionImitator is a special type of EventImitator that maps x and y movement to a spring. This is done with MotionProperty enums, which specifies which methods to call in a MotionEventobject. For example, MotionProperty.X.getValue(MotionEvent) calls event.getX(). It also specifies the view property to animate - MotionEvent.X.getViewProperty() corresponds toView.TRANSLATION_X. This is useful for the Actor builder later on. In addition, tracking and following strategies allow for customization of how the event value is mapped to the spring.
Tracking Strategies
Two tracking strategies are available to configure how an imitator tracks its imitatee.
TRACK_ABSOLUTE maps the imitatee value directly to the spring.
TRACK_DELTA maps the change in the imitatee value (relative to the initial touch) to the spring.
Follow Strategies
Two follow strategies are available to configure how the spring is updated.
FOLLOW_EXACT maps the imitatee value directly to the current and end value of the spring.
FOLLOW_SPRING maps the imitatee value to the end value of the spring (which allows the spring to overshoot the current position)
Imitating Springs
A SpringImitator is also a SpringListener. When the Spring it is imitating updates, it updates the end value of the Spring it is controlling. Usage is simple:
SpringSystem springSystem = SpringSystem.create();
Spring leader = springSystem.createSpring();
Spring follower = springSystem.createSpring();
SpringImitator follow =
new
SpringImitator(follower);
leader.addListener(follow);
Actors
Even though backboard reduces a significant amount of boilerplate code, the Actor class further simplifes view motion by connecting each component together. It also manages aView.onTouchListener() (a MotionListener), which it attaches to the View automatically (this can be disabled). Here is how to create one:
Actor actor =
new
Actor.Builder(SpringSystem.create(), view)
.addTranslateMotion(MotionProperty.X)
.build();
in two dimensions:
Actor actor =
new
Actor.Builder(SpringSystem.create(), view)
.addTranslateMotion(MotionProperty.X)
.addTranslateMotion(MotionProperty.Y)
.build();
Two calls to addTranslateMotion(MotionProperty) are needed because each axis is independent of the other. The builder will create an OnTouchListener and attach it to the View, as well as aSpring with the default settings. A Performer is also created and attached to the Spring. When there is a touch event, it is passed to the MotionImitator, which perturbs the spring, which moves the view.
It is also possible to supply your own SpringSystem, Spring, MotionImitator and Performer, and the builder will properly connect them. The first example above can also be expressed as:
SpringSystem springSystem = SpringSystem.create();
Spring spring = springSystem.createSpring();
Actor verbose =
new
Actor.Builder(springSystem, view)
.addMotion(spring,
new
MotionImitator(spring, MotionProperty.X),
new
Performer(view, View.TRANSLATION_X)
.build();
The View can be also left out of the constructor of the Performer and the Spring out of theMotionImitator (using the default SpringConfig), since the builder will connect them.
Actor walk =
new
Actor.Builder(SpringSystem.create(), walker)
.addMotion(
new
MotionImitator(MotionProperty.X),
new
Performer(View.TRANSLATION_X))
.build();
which can be further simplified to
Actor run =
new
Actor.Builder(SpringSystem.create(), runner).addMotion(MotionProperty.X, View.TRANSLATION_X).build();
and for more sugar, the previous case:
Actor bolt =
new
Actor.Builder(SpringSystem.create(), bolter).addTranslateMotion(MotionProperty.X).build();
Actor Options
requestDisallowTouchEvent() causes the Actor to callViewParent.requestDisallowTouchEvent(true) which is helpful when the view is inside aListView or another view that captures touch events.
dontAttachMotionListener() tells the builder to not attach the MotionListener to the View, which is useful when you want to attach your own OnTouchListener to the view.
Dependencies
rebound
- Android基于Facebook Rebound的动画效果框架Backboard demo (非常炫酷)
- Android基于Facebook Rebound的动画效果框架Backboard demo (非常炫酷)
- 介绍Facebook的rebound动画库
- 让动画不再僵硬:Facebook Rebound Android动画库介绍
- 让动画不再僵硬:Facebook Rebound Android动画库介绍
- Rebound-Android的弹簧动画库
- Rebound-Android的弹簧动画库
- Rebound-Android的弹簧动画库
- Android弹性反弹:Facebook Rebound
- Facebook Rebound 弹性动画库 源码分析
- Rebound动画框架简单介绍
- facebook rebound
- Android弹簧动画 Rebound实战
- Facebook Rebound(没找到Android版本,这里是IOS的介绍,类使用都差不多)
- Facebook-Rebound探索发现
- Facebook rebound库编译之后,安装时出现的bug
- 开源动画框架Facebook的Pop
- android的炫酷动画框架
- C++Primer第5版读书笔记(第6章)
- nginx使用ssl模块配置HTTPS支持
- 按键事件笔记
- 输入数字,输出数字读法
- 88. Merge Sorted Array
- Android基于Facebook Rebound的动画效果框架Backboard demo (非常炫酷)
- LINUX右键菜单当前路径打开终端
- Redis学习小结
- 用两个栈实现队列和用两个队列实现一个栈
- Linux下,串口,FIFO循环队列,状态机接收程序
- myeclipse 2015 stable 2.0连接mysql URL错误
- hive本地安装
- PHP进阶:删除文件
- 最近研究xcodebuild批量打包的一些心得