Android – avoid layout change animations in custom views, which are updated in WindowManager

I have a custom relativelayout, and I even set setlayouttransition (null) I use ((WindowManager) context.getsystemservice (context. Window_service)) to add this custom view to windowmanager.updateviewlayout (this, layoutparams);

I change the view in the custom view and change the LayoutParams of WindowManager, and then call updateViewLayout.

I think the change of layoutparams in WindowManager is animated, but I'm not sure

How do i disable all animations?

resolvent:

This is a bit annoying. Android has animated all window changes, and they have set a flag to disable it as private. You can disable window animation using reflection

    WindowManager.LayoutParams wp = new WindowManager.LayoutParams();
    String className = "android.view.WindowManager$LayoutParams";
    try {
        Class layoutParamsClass = Class.forName(className);

        Field privateFlags = layoutParamsClass.getField("privateFlags");
        Field noAnim = layoutParamsClass.getField("PRIVATE_FLAG_NO_MOVE_ANIMATION");

        int privateFlagsValue = privateFlags.getInt(wp);
        int noAnimFlag = noAnim.getInt(wp);
        privateFlagsValue |= noAnimFlag;

        privateFlags.setInt(wp, privateFlagsValue);

        // Dynamically do stuff with this class
        // List constructors, fields, methods, etc.

    } catch (ClassNotFoundException e) {
        Logger.l.e(e.toString());
        // Class not found!
    } catch (Exception e) {
        Logger.l.e(e.toString());
        // UnkNown exception
    }

Now WP will not animate layout changes. Please note that you may see flickers when you change the window size. I have no way to solve this problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>