Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

SpringUtil question #55

Closed
jjhesk opened this issue Feb 27, 2015 · 4 comments
Closed

SpringUtil question #55

jjhesk opened this issue Feb 27, 2015 · 4 comments

Comments

@jjhesk
Copy link

jjhesk commented Feb 27, 2015

Would you explain to me how to understand these params by your sample app

  // On each update of the spring value, we adjust the scale of the image view to match the
      // springs new value. We use the SpringUtil linear interpolation function mapValueFromRangeToRange
      // to translate the spring's 0 to 1 scale to a 100% to 50% scale range and apply that to the View
      // with setScaleX/Y. Note that rendering is an implementation detail of the application and not
      // Rebound itself. If you need Gingerbread compatibility consider using NineOldAndroids to update
      // your view properties in a backwards compatible manner.
      float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);

At the end, I would like to apply the spring's 0 to 1 to 400dp to 100 dp in the layout height. Please let me know how to apply it into SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);. Thank you so much.

@jjhesk
Copy link
Author

jjhesk commented Feb 27, 2015

is the answer going to be

SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 100, 400); ?

@willbailey
Copy link
Contributor

If you want 0 to be 400 and 1 to be 100 then it would be:
SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 400, 100);

of course that's going to be px if you want dp you'll need to convert your dp to px values separately.

@jjhesk
Copy link
Author

jjhesk commented Feb 27, 2015

how do we make a conversion dynamically?

@jasleensingh
Copy link

If you have the dimension values (400dp, 100dp) in an xml somewhere, you can use:
int px = context.getResources().getDimensionPixelSize(<res-id>);
to convert the dp value to pixels. Otherwise, there are a number of ways to do a direct conversion, one of which is:
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, <size_in_dp>, context.getResources().getDisplayMetrics());

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants