如何禁用“窗口动画比例”在Android 4.0+设备上以编程方式? [英] How to disable "Window animation scale" programmatically on Android 4.0+ devices?

查看:471
本文介绍了如何禁用“窗口动画比例”在Android 4.0+设备上以编程方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用服务,使用 WindowManager 显示视图,每次使用

I'm using a Service that displays a view using WindowManager, and animation occurs every time I change the view's size using

windowManagerLayoutParams.height = newHeight;
((WindowManager) getSystemService(WINDOW_SERVICE)).updateViewLayout(mMainLayout, windowManagerLayoutParams);

如果我手动禁用缩放动画,则不会发生动画。
手动禁用缩放动画,如下所示:
http://www.cultofandroid.com/11143/android-4-0-tip-how-to-find-and-disable-animations-for -a-snappier-experience /

If I disable manually the scale animations, no animation occurs. Scale animation disabled manually like so: http://www.cultofandroid.com/11143/android-4-0-tip-how-to-find-and-disable-animations-for-a-snappier-experience/

有没有办法以编程方式为我的应用程序禁用窗口缩放动画?

推荐答案

我在SystemUI包中处理系统覆盖时遇到了同样的问题,并决定挖掘源代码来查看是否我可以找到解决方案。 WindowManager.LayoutParams 有一些隐藏的好东西可以解决这个问题。诀窍是使用 WindowManager.LayoutParams 的privateFlags成员,如下所示:

I just had this same problem while working on a system overlay in the SystemUI package and decided to dig through the source to see if I could find a solution. WindowManager.LayoutParams has some hidden goodies that can solve this problem. The trick is to use the privateFlags member of WindowManager.LayoutParams like so:

windowManagerLayoutParams.privateFlags |= 0x00000040;

如果你看一下WindowManager.java 您将看到0x00000040是PRIVATE_FLAG_NO_MOVE_ANIMATION的值。对我来说,当我通过 updateViewLayout()

If you look at line 1019 of WindowManager.java you'll see that 0x00000040 is the value for PRIVATE_FLAG_NO_MOVE_ANIMATION. For me this did stop window animations from occurring on my view when I change the size via updateViewLayout()

我有工作系统包的优势,所以我能够直接在我的代码中访问privateFlags,但如果要访问此字段,则需要使用反射。

I had the advantage of working on a system package so I am able to access privateFlags directly in my code but you are going to need to use reflection if you want to access this field.

这篇关于如何禁用“窗口动画比例”在Android 4.0+设备上以编程方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆