本文介绍了Android的appwide视图叠加(HUD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的整个应用程序来覆盖一个视图,所有的活动包括在内。你可以把它作为一个HUD(抬头显示器)在我的应用程序。该应用程序有多个活动,包括标签的活动和HUD不以任何方式与用户交互,它只是显示信息,同时让用户与应用互动,她通常会。
我想这个HUD调试目的,所以我(和其他人)可以监视应用程序的活动和状态时,手机没有连接到调试机器(现场测试)。

I want to overlay a view over my entire app, all activities included. Think of it as a HUD (Head Up Display) over my app. The app has multiple activities, including a tab activity and the HUD doesn't interact with the user in any way, it just displays information while letting the user interact with the app as she would normally.I want this HUD for debugging purposes so I (and others) can monitor app activity and state when the phone is not attached to a debugging machine (field testing).

我怎么添加这样的看法?

How do I do add such a view?

我使用WindowManager.addView()像这样尝试:

I've tried using WindowManager.addView() like so:

        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
             LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
             WindowManager.LayoutParams.TYPE_APPLICATION,
             WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                  | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
             PixelFormat.TRANSLUCENT);
        windowManager.addView(hudView, lp);

不过,HUD似乎并不在前台要坚持,当我推出新的活动,它只是消失了。

But the HUD doesn't seem to persist in the foreground when I launch new activities it simply disappears.

推荐答案

我知道这是一个老问题,但我想我无论如何回答,因为这帮助了我。我试图让在OpenGL游戏运行的HUD,这完全适用于这一点。

I know this is an old question, but I thought I'd answer anyway since this helped me out. I was trying to get an HUD running in an openGL game and this works perfectly for that.

既然你已经在使用的窗口管理器的HUD显示,所有你需要做的,让这活动之间的持续性是调用 windowManager.addView(hudView,LP); 在每个活动的 onResume()方法。不知道内存的意义是什么,但(即是被布置在窗口管理器从屏幕在切换活动中删除的视图),但至少它会在整个应用程序保持HUD了。

Since you already have the HUD displaying using the window manager, all you need to do to keep it persistant between activities is to call windowManager.addView(hudView, lp); in each activity's onResume() method. Not sure what the memory implications are though (i.e. is the view being disposed of when the window manager removes it from the screen upon switching activities), but at least it will keep the HUD up throughout the entire app.

这篇关于Android的appwide视图叠加(HUD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 19:16