4

I'm trying to use PathInterpolator from android.support.v4.view.animation.PathInterpolatorCompat because PathInterpolator won't work on my device API 18 since it was added in API 21.

I've downloaded the support repository, and included the following build.gradle under the app directory:

compile "com.android.support:support-v4:21.0.0"

I'm trying to use it like this:

PathInterpolator p_interpolator = new PathInterpolator(.5f,1.0f);

However, in Android Studio it prompts the import from: android.view.animation.PathInterpolator instead of giving me an option for the compat version.

What do I need to do?

Editor's Note: the right usage of PathInterpolatorCompat is (as @fernforce mentioned in a comment on the accepted answer):

PathInterpolator p_interpolator = PathInterpolatorCompat.create(.5f,1.0f);
hata
  • 11,633
  • 6
  • 46
  • 69
fernforce
  • 163
  • 2
  • 8
  • I tried including it manually: import android.support.v4.view.animation.PathInterpolatorCompat; but the "animation" part is not found. Maybe I could have setup my own class and broke out my old calculus textbook to achieve the darn solution. – fernforce May 25 '15 at 06:26
  • check this answer https://stackoverflow.com/a/67636215/4797289 – Rasoul Miri May 22 '21 at 08:31

1 Answers1

5

PathInterpolatorCompat is available in the support library since version 22.1.0. To fix that just change the gradle declaration to use the latest version:

compile "com.android.support:support-v4:22.1.1"

For more informations see the Support Library v22.1 announcement.

rciovati
  • 27,603
  • 6
  • 82
  • 101
  • This is the correct answer, I just don't have enough reputation to vote it. The implementation is as follows: Interpolator p_interpolator = PathInterpolatorCompat.create(0.5f,1.0f); – fernforce May 25 '15 at 06:50
  • you can check this answer https://stackoverflow.com/a/67636215/4797289 – Rasoul Miri May 22 '21 at 08:31