rebound是facebook的开源动画库

网址:http://www.jcodecraeer.com/a/opensource/2015/0121/2338.html

介绍:

rebound是facebook的开源动画库。可以认为这个动画库是独立于android Framework之外的一种动画实现。

运行效果:

使用说明:

Rebound官方主页

 

1.首先添加Rebound库依赖

Rebound提供了三种方式引入,当然在Android Studio下还是推荐使用Gradle方式。

添加Gradle依赖(推荐)

dependencies {
compile 'com.facebook.rebound:rebound:0.3.6'
}

下载Rebound Jar文件,导入工程,添加Maven依赖

<dependency>
    <groupId>com.facebook.rebound</groupId>
    <artifactId>rebound</artifactId>
    <version>0.3.6</version>
</dependency>

2.首先创建一个SpringSystem对象

SpringSystem mSpringSystem = SpringSystem.create();

3.添加一个“弹簧”到系统

Spring mSpring = mSpringSystem.createSpring();

4.添加监听器

mSpring.addListener(this);
//实现SpringListener接口,需要实现下面方法
@Override
    public void onSpringUpdate(Spring spring) {
}
@Override
    public void onSpringAtRest(Spring spring) {
}
@Override
    public void onSpringActivate(Spring spring) {
}
@Override
    public void onSpringEndStateChange(Spring spring) {
}

 

5.设置动画结束值

mSpring.setEndValue(1f);

6.在弹簧更新数据是对图片进行对应伸缩

public void onSpringUpdate(Spring spring) {
    float value = (float) spring.getCurrentValue();
    float scale = 1f - (value * 0.5f);
    mImageToAnimate.setScaleX(scale);
    mImageToAnimate.setScaleY(scale);
}

 

通过上面几个步骤可以很方便的实现弹簧阻尼效果的图片伸缩。

参考 :http://qichaochen.github.io/2014/11/21/107-Facebook-Rebound-Demo/ 

posted @ 2017-06-21 13:54  一只呆萌的萌呆  阅读(1593)  评论(0编辑  收藏  举报