2

SwipeRefreshLayout uses a set variable for the ending animation. In certain use-cases, I need to change this to 0 but I can't figure out how. Here's the variable:

private static final int SCALE_DOWN_DURATION = 150;

Any help would be greatly appreciated.

Psest328
  • 6,575
  • 11
  • 55
  • 90

1 Answers1

0

You will need to access the private Field, and update the value to 0, using the Java reflection APIs. Because the field is final, you will need to update its modifiers to remove this information, as described in this post.

Field duration = SwipeRefreshLayout.class.getDeclaredField("SCALE_DOWN_DURATION");
duration.setAccessible(true); // counteract private modifier

Field mods = Field.class.getDeclaredField("modifiers"); // retrieve modifiers for the constant field
mods.setAccessible(true);
int finalValue = mods.getModifiers() & ~Modifier.FINAL; // flip final value, allowing mutation of the field
mods.setInt(mods, finalValue);
duration.setInt(hack, 0); // set value

It should go without saying, but as this is an implementation detail of SwipeRefreshLayout there's no guarantee that this won't break without warning in the future. If you require several modifications like this, then forking the class and maintaining your own version may be a better solution.

Community
  • 1
  • 1
fractalwrench
  • 4,028
  • 7
  • 33
  • 49