避免在WindowManager中更新的自定义视图中的布局更改动画 [英] Avoid layout change animations in custom view, that's updated in the WindowManager

查看:803
本文介绍了避免在WindowManager中更新的自定义视图中的布局更改动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的 RelativeLayout ,甚至设置了 setLayoutTransition(null); 。我使用((WindowManager)context.getSystemService(Context.WINDOW_SERVICE))。updateViewLayout(this,layoutParams);

I have a custom RelativeLayout and I even have set setLayoutTransition(null);. I add this custom view to the WindowManager with ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).updateViewLayout(this, layoutParams);

我更改了自定义视图中的视图,并更改了 WindowManager LayoutParams 和然后调用 updateViewLayout ...

I change views in the custom view AND I change the LayoutParams for the WindowManager and afterwards call updateViewLayout...

我认为, LayoutParams的变更 WindowManager 的动画是动画,但我不确定...

I think, the chang of the LayoutParams for the WindowManager is animated, but I'm not sure...

如何我禁用所有动画吗?

How can I disable ALL animations?

推荐答案

这有点烦人。 Android对所有窗口更改进行动画处理,并且已将其标记为私有。您可以使用 reflection

This one's a little annoying. Android animates all window changes, and they've made the flag to disable it private. You can disable window animations 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
    }

现在 wp 不会设置布局的动画。请注意,更改窗口大小时,您可能会看到闪烁。我还没有找到解决该问题的方法。

Now wp will not animate layout changes. Note you'll probably see flicker when you change the window size. I haven't found a way to work around that yet.

这篇关于避免在WindowManager中更新的自定义视图中的布局更改动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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