Ant*_*vin 5 animation android android-vectordrawable
是否可以以相反的顺序播放AnimatedVectorDrawable的动画?
如果你查看 AnimatedVectorDrawable 源代码,你会发现该方法
/**
* Reverses ongoing animations or starts pending animations in reverse.
* <p>
* NOTE: Only works if all animations support reverse. Otherwise, this will
* do nothing.
* @hide
*/
public void reverse()
Run Code Online (Sandbox Code Playgroud)
您可以使用反射来调用此方法。例如这样:
private boolean mAnimationReversed = false;
public void startAnimation() {
if(mAnimationReversed) {
try {
Method reverse = mDrawable.getClass().getMethod("reverse");
reverse.invoke(mDrawable);
} catch (IllegalAccessException| NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
}
mDrawable.start();
mAnimationReversed = !mAnimationReversed;
}
Run Code Online (Sandbox Code Playgroud)
刚刚验证:适用于 API21,但不适用于 API24 :-(
| 归档时间: |
|
| 查看次数: |
1275 次 |
| 最近记录: |