在Android开发者选项中关于动画的设置有三个选项:窗口动画缩放、过渡动画缩放、动画程序时长缩放。
这三个“缩放”的具体含义如下:
窗口动画缩放:
Scaling factor for normal window animations. Setting to 0 will disable window animations. //作用于非Activity窗口
过渡动画缩放:
Scaling factor for activity transition animations. Setting to 0 will disable window animations. //作用于Activity窗口
动画程序时长缩放:
Scaling factor for Animator-based animations. This affects both the start delay and duration of all such animations. Setting to 0 will cause animations to end immediately. The default value is 1.//作用于全局的动画时长
代码关闭Android过度缩放动画
获取WindowManager句柄,通过binder调用WindowManagerService中setAnimationScale方法
//setAnimationScale(0.0f, 0.0f, 1.0f); /** * @para * value1 窗口动画缩放 * value2 过渡动画缩放 * value3 Animator时长缩放 */ private void setAnimationScale(float value1, float value2, float value3) { IWindowManager mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE)); try { float[] values = {value1, value2, value3}; mWindowManager.setAnimationScales(vars); } catch (RemoteException e) { e.printStackTrace(); } }
修改开发者选项中动画缩放的默认值
frameworks/base/core/res/res/values/config.xml
<item name="config_appTransitionAnimationDurationScaleDefault" format="float" type="dimen">0.5</item>
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
private float mWindowAnimationScaleSetting = 0.5f; private float mTransitionAnimationScaleSetting = 0.5f; private float mAnimatorDurationScaleSetting = 0.5f;
当然,最好还是修改framework的默认值。(framework部分没有实践过,需要自己去尝试一下)
参考
1.《Android开发者选项中动画相关配置,看这篇就够了!!!》