【问题标题】:SwipeRefreshLayout - Change animation timingSwipeRefreshLayout - 更改动画时间
【发布时间】:2016-04-15 19:09:39
【问题描述】:

SwipeRefreshLayout 为结束动画使用了一个 set 变量。在某些用例中,我需要将其更改为 0,但我不知道如何。这是变量:

private static final int SCALE_DOWN_DURATION = 150;

任何帮助将不胜感激。

【问题讨论】:

  • 最好只获取源代码并修改它以满足您的需求

标签: android view swiperefreshlayout


【解决方案1】:

您需要使用 Java 反射 API 访问私有字段,并将值更新为 0。由于该字段是最终字段,因此您需要更新其修饰符以删除此信息,如 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

不言而喻,但由于这是 SwipeRefreshLayout 的实现细节,因此无法保证将来不会在没有警告的情况下中断。如果您需要像这样进行多次修改,那么分叉类并维护您自己的版本可能是更好的解决方案。

【讨论】:

  • "无法解析方法'getDeclaredModifiers(java.lang.string)'"
  • 将方法名称更新为 getDeclaredField(java.lang.String)
  • java.lang.NoSuchFieldException:Ljava/lang/reflect/Field 类中没有字段修饰符; ('java.lang.reflect.Field'的声明出现在/system/framework/core-libart.jar)
猜你喜欢
  • 1970-01-01
  • 2013-01-18
  • 1970-01-01
  • 2011-11-24
  • 2014-07-28
  • 1970-01-01
  • 1970-01-01
  • 2017-07-27
  • 1970-01-01
相关资源
最近更新 更多