introduction

official site:http://facebook.github.io/rebound
github : https://github.com/facebook/rebound
Rebound是facebook推出的一个弹性动画库,可以让动画看起来真实自然,像真实世界的物理运动,带有力的效果,使用的参数则是facebook的origami中使用的。
官网上有一个简单的JS版本来做demo,如果说到evernote、LinkedIn、flow等应用也在使用这个动画库,是不是会显得更厉害些呢。

具体效果,可以看看QQ空间 Android独立版客户端中,抽屉打开的icon效果,以及底部加号点开后的icon效果,是我当年在的时候做的。

usage

1
2
3
4
5
6
7
8
9
10
Spring spring = mSpringSystem
.createSpring()
.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(86, 7))
.addListener(new SimpleSpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
float value = (float) spring.getCurrentValue();
ViewHelper.setTranslationX(view, value);
}
});

上面的短短代码就可以给一个view加上自然的从左向右进入回弹效果。

类似地

1
2
3
4
5
6
7
8
9
10
11
12
Spring spring = mSpringSystem
.createSpring()
.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(86, 7))
.addListener(new SimpleSpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
float value = (float) spring.getCurrentValue();
float scale = 1f - value;
ViewHelper.setScaleX(mItemIconViewList.get(index), scale);
ViewHelper.setScaleY(mItemIconViewList.get(index), scale);
}
});

就可以给view加上一个从小变大然后略有回弹的效果。

如果想要做很多view的连锁动画怎么办?Rebound也提供了SpringChain这个接口。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
for (int i = 0; i < viewCount; i++) {
final View view = new View(context);
view.setLayoutParams(
new TableLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
1f));
mSpringChain.addSpring(new SimpleSpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
float value = (float) spring.getCurrentValue();
view.setTranslationX(value);
}
});
int color = (Integer) evaluator.evaluate((float) i / (float) viewCount, startColor, endColor);
view.setBackgroundColor(color);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return handleRowTouch(v, event);
}
});
mViews.add(view);
rootView.addView(view);
} getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getViewTreeObserver().removeOnGlobalLayoutListener(this);
List<Spring> springs = mSpringChain.getAllSprings();
for (int i = 0; i < springs.size(); i++) {
springs.get(i).setCurrentValue(-mViews.get(i).getWidth());
}
postDelayed(new Runnable() {
@Override
public void run() {
mSpringChain
.setControlSpringIndex(0)
.getControlSpring()
.setEndValue(0);
}
}, 500);
}
});

就做出了一个view和view的牵引位移动画效果。

最新文章

  1. .net Global.asax文件使用
  2. cell当中的按钮如何获得cell内容
  3. C# WPF获取任务栏时间区域的Rectangle
  4. 后台跳转到登录页嵌套在iframe的问题(MVC例)
  5. Python高手之路【八】python基础之requests模块
  6. BestCoder Round #88
  7. 打印web页面指定区域的三种方法
  8. [转载]HDFS的&#39;Block&#39;和MapReduce的&#39;Split&#39;之间的关系和区别
  9. 分享,iOS国家手机区号代码.plist
  10. jQuery总结---版本一
  11. 20190421-那些年使用过的CSS预处理器(CSS Preprocessor)之Sass and Less
  12. hello1和hello2代码分析
  13. Solr简单使用
  14. sql 双表或多表的连接查询 join
  15. C#基础(204)--对象初始化器,基本数据类型与引用数据类型特点总结,ref,out关键字的使用
  16. win7+win10系统使用日常经验集锦
  17. beginner_json_setting
  18. PAT L2-013 红色警报(并查集求连通子图)
  19. double float的精度问题
  20. 各种C#数组的定义和初始化

热门文章

  1. python学习第二天:数字与字符串转换及逻辑值
  2. [记录 ]升级IOS 9 和 XCode 7 引起的问题
  3. mac配置svn服务器
  4. 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记19 为Demo添加手势
  5. IOS 应用程序启动加载过程(从点击图标到界面显示)
  6. Mysql 的变量
  7. 重构if...else...或者switch程序块 为 中介者(Mediator)模式.的思考
  8. 改善EF代码的方法(上)
  9. [转]优化PHP程序的方法
  10. java oop