How to disable "Window Scaling" programmatically on Android 4.0+ devices?

I use a Service that displays a view using WindowManager , and an animation occurs every time I resize a view using

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

If I manually disable large-scale animations, the animation will not happen. Large-scale animation is manually disabled: http://www.cultofandroid.com/11143/android-4-0-tip-how-to-find-and-disable-animations-for-a-snappier-experience/

Is there a way to disable window scale animations for my application programmatically?

+7
source share
3 answers

I had the same problem while working on a system overlay in the SystemUI package and decided to break through the source to find out if I could find a solution. WindowManager.LayoutParams has some hidden properties that can solve this problem. The trick is to use the privateFlags member of WindowManager.LayoutParams , for example:

 windowManagerLayoutParams.privateFlags |= 0x00000040; 

If you look at line 1019 of WindowManager.java , you will see that 0x00000040 is the value for PRIVATE_FLAG_NO_MOVE_ANIMATION. For me, this stopped the window animation on my view when I resize using updateViewLayout ()

I had the advantage of working with the system package, so I can access privateFlags directly in my code, but you will need to use reflection if you want to access this field.

+12
source

As pointed out by @clark, this can be changed using reflection:

 private void disableAnimations() { try { int currentFlags = (Integer) mLayoutParams.getClass().getField("privateFlags").get(mLayoutParams); mLayoutParams.getClass().getField("privateFlags").set(mLayoutParams, currentFlags|0x00000040); } catch (Exception e) { //do nothing. Probably using other version of android } } 
+4
source

Have you tried Activity#overridePendingTransition(0, 0) ?

Check the documentation :

Call immediately after one of the options startActivity (Intent) or finish () to specify an explicit transition animation to perform the following.

0
source

All Articles