Animate Your View With Facebook Rebound

Shahadat Hossain Shaki
1 min readJun 19, 2019

--

Sometimes we want to show some animation while a user interacts with our view. Like user giving like, love, comment, etc.

Rebound is a java library that models spring dynamics. Rebound spring models can be used to create animations that feel natural by introducing real-world physics to your application.

Let me show you the easiest way to implement this.

Implement the library on your app level Gradle file “build.gradle(Module: app).

implementation 'com.facebook.rebound:rebound:0.3.8'

I have to build a method which takes the view and show spring on that view.

public static void springView(final View view) {

SpringSystem mSpringSystem;
Spring mSpring;
double TENSION = 200;
double DAMPER = 15;

mSpringSystem = SpringSystem.create();
mSpring = mSpringSystem.createSpring();
SpringConfig config = new SpringConfig(TENSION, DAMPER);
mSpring.setSpringConfig(config);


mSpring.setCurrentValue(1);

mSpring.addListener(new SimpleSpringListener() {

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

mSpring.setEndValue(-.1);

}

Increase or decrease TENSION and DAMPER value to control the spring animation. I found this value perfect for me.

Hope you build something exciting :) :)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shahadat Hossain Shaki
Shahadat Hossain Shaki

Written by Shahadat Hossain Shaki

Co-Founder and Android developer of Happihub. Loves to develop things.

No responses yet

Write a response