0

I got this error setCropToPadding() NoSuchMethodError when running my app on version < 4.1. How do I set cropToPadding to the image loaded to a GridView cell without ImageView XML?

Please help!

jerrytouille
  • 1,238
  • 1
  • 13
  • 28

2 Answers2

1

Found this to be the best answer for my issue... for now. Copy and paste over and it simply worked!

try {
    Field field = ImageView.class.getDeclaredField("mCropToPadding");
    field.setAccessible(true);
    field.set(imageView, true);
} catch (Exception e) {
    e.printStackTrace();
}

Reference: https://gist.github.com/mrmans0n/2924241

jerrytouille
  • 1,238
  • 1
  • 13
  • 28
0

setCropToPadding() was introduced in API level 16 (JellyBean). Look at the top right: https://developer.android.com/reference/android/widget/ImageView.html#setCropToPadding(boolean)

Karakuri
  • 38,365
  • 12
  • 84
  • 104