Rebound library facebook

787 views Asked by At

I'm trying to use this library, and I noticed there is a configuration panel you can add in the xml :

 <com.facebook.rebound.ui.SpringConfiguratorView
    android:id="@+id/spring_configurator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    />

which affects this code:

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);
  }
});

I'm trying to do the same thing the configuration panel does just without it? Anyone knows how to do it? Here is an example of what I want to do - without the panel : http://facebook.github.io/rebound/

1

There are 1 answers

0
jds17 On

If you're asking about how to set the Tension and Friction for your Spring, you have to use SpringConfig

In your case you can set the SpringConfig of an individual spring by calling it like so:

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);
  }
});

// Specify your own TENSION or FRICTION value as an int
SpringConfig config = new SpringConfig(TENSION, FRICTION);
spring.setSpringConfig(config);