︿( ̄︶ ̄)︿我是路过的DEMO : github.com/CarGuo/Anim…
java
安利Facebook开源的弹簧动画库,模拟物理弹簧的效果,让直男♂的你今后软下来,产品经理不再须要担忧交互过硬了(✿◡‿◡)。git
rebound模拟的是物理效果,这里主要是有两个关键点:Tension(拉力系数)、Friction(摩擦系数)。Tension越大♀,弹性效果就越大,很符合逻辑是吧( ̄o ̄) ;Friction越大,受到的阻力就会越大,弹性效果就会下降。这里注意的是,弹性虽好,但摩擦力也是必须的哟,学过物理的你应该知道,没有摩擦力,根本停不下来啊,摩擦力太大,又进不···呸呸呸,又弹性很差。github
下方是facebook官方的demo,使用默认的F和T系数,建立一个Spring ,经过设置开始\接结束的系数,在监听过程当中经过getCurrentValue,设置你想要的移动\放大\透明度等等效果,来实现你的动画,感受是否是很ValueAnimation,简单易上手。spring
有兴趣的能够去rebound下载官方demo,若是发现官方demo跑不来,能够试试我fork修改后的demo哟:github.com/CarGuo/rebo…ide
// Create a system to run the physics loop for a set of springs.
SpringSystem springSystem = SpringSystem.create();
// Add a spring to the system.
Spring spring = springSystem.createSpring();
// Add a listener to observe the motion of the spring.
spring.addListener(new SimpleSpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
// You can observe the updates in the spring
// state by asking its current value in onSpringUpdate.
float value = (float) spring.getCurrentValue();
float scale = 1f - (value * 0.5f);
myView.setScaleX(scale);
myView.setScaleY(scale);
}
});
// Set the spring in motion; moving from 0 to 1
spring.setEndValue(1);复制代码
进入正题:oop
一、首先咱们定义一个布局,包含四个圆形TAB,让它们呈现以下图效果。而后把它们都设置为GONE。布局
二、建立一个Spring用于执行动画。动画
SpringChain
,能够自定义咱们想要的拉力和摩擦力系数,从左到右是主拉力,主摩擦力,辅助拉力,辅助摩擦力。看下面,上面一堆废话,那个傻X说了那么多,哇塞,代码好简单啊(^o^)/,是否是以为站在巨人的肩膀上,很自豪啊。收回动画就是把弹出的反过来便可,妥妥的。spa
SpringChain springChain = SpringChain.create(40, 6, 50, 7);
for (int i = 0; i < list.size(); i++) {
final View view = list.get(i);
springChain.addSpring(new SimpleSpringListener() {
@Override
public void onSpringActivate(Spring spring) {
super.onSpringActivate(spring);
view.setVisibility(VISIBLE);
}
@Override
public void onSpringUpdate(Spring spring) {
view.setTranslationY((float) spring.getCurrentValue());
float scale = (1 + 2 * (float) spring.getCurrentValue() / mainView.getHeight());
view.setScaleX(scale);
view.setScaleY(scale);
}
});
}
List<Spring> springs = springChain.getAllSprings();
for (int i = 0; i < springs.size(); i++) {
springs.get(i).setCurrentValue(mainView.getHeight());
}
springChain.setControlSpringIndex(0).getControlSpring().setEndValue(0);复制代码
最后咱们额外来个副菜,既然弹出\收起都有效果,那么“碰”起来也要有效果才对,这里咱们就参考微博的菜单,在点击时候执行最后的动画效果。3d
这个相对更加简单,咱们使用系统的AnimationSet ,将点击的TAB放大和透明化动画一块儿执行,将其余的TAB同时缩小和透明化,动画结束时让tab隐藏起来,这样一个完整的菜单动画就结束啦。(。・・)ノ是否是好短啊,都说好短啦。
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.setInterpolator(new AccelerateInterpolator());
animationSet.setDuration(200);
animationSet.setFillAfter(false);
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(GONE);
ButtonClickLogin(view);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
view.startAnimation(animationSet);复制代码
两句。