什么是窗口管理器,在Android的? [英] What is windowManager in android?

查看:252
本文介绍了什么是窗口管理器,在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Google并没有直接和明确的答案。

I tried googling it and there is direct and clear cut answer.

在开发者网站的定义不明确无论是。

The developer website's definition is not clear either.

的应用程序使用交谈窗口管理器的界面。 使用Context.getSystemService(Context.WINDOW_SERVICE),以获得其中之一。

The interface that apps use to talk to the window manager. Use Context.getSystemService(Context.WINDOW_SERVICE) to get one of these.

有人可以用普通小学六年级的英语解释这是什么?我怎么可以用它来创建仍通过一些工作之外的活动浮动对象,即使我从一个移动到另一个?

Can someone with plain 6th grade English explain what it is ? And how can I use it to create a floating object that remains via several activties, even though I moved from one to the other ?

推荐答案

而Android窗口管理是一个系统服务,这是负责管理窗口的z顺序列表,其中窗口是可见的,以及它们是如何奠定了屏幕。除此之外,它会自动打开或关闭一个应用程序时,或旋转屏幕进行窗口切换和动画。

The Android WindowManager is a system service, which is responsible for managing the z-ordered list of windows, which windows are visible, and how they are laid out on screen. Among other things, it automatically performs window transitions and animations when opening or closing an app or rotating the screen.

每个活动都有一个用来显示其在屏幕上内容的窗口。当你打电话的setContentView上的活动,它重视这一观点对这个活动的默认窗口。默认的窗口填满整个屏幕,使您的活动的窗口隐藏的任何其他活动 - 在窗口管理器将显示任何窗口的顶部。所以,通常你不必担心窗户 - 你只是创建活动和Android将完成剩下的给你。

Every activity has a Window that is used to display its content on the screen. When you call setContentView on an activity, it attaches that view to the activity's default window. The default window fills the screen, so that your activity's window hides any other activities -- the WindowManager will display whichever window is on top. So normally you don't need to worry about windows - you just create an activity and Android will do the rest for you.

但你需要的,如果你想要做一些不寻常如创建浮动窗口不填充屏幕与窗口管理器进行交互。如果你想创建一个浮动窗口,是在其他应用程序前面看见,你不能用一个活动,因为当其他应用程序来到前台的活动将停止,并且其窗口会被隐藏或销毁。相反,你需要从后台服务显示一个窗口。例如:

But you need to interact with the WindowManager if you want to do something unusual like create floating windows that don't fill the screen. If you want to create a floating window that is visible in front of other applications, you can't use an activity because your activity will stop when another app comes to the foreground, and its window will be hidden or destroyed. Instead you need to display a window from a background service. For example:

WindowManager.LayoutParams p = new WindowManager.LayoutParams(
    // Shrink the window to wrap the content rather than filling the screen 
    WindowManager.LayoutParams.WRAP_CONTENT,
    WindowManager.LayoutParams.WRAP_CONTENT,
    // Display it on top of other application windows, but only for the current user
    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
    // Don't let it grab the input focus
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
    // Make the underlying application window visible through any transparent parts
    PixelFormat.TRANSLUCENT);

// Define the position of the window within the screen
p.gravity = Gravity.TOP | Gravity.RIGHT;
p.x = 0;
p.y = 100;

WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
windowManager.addView(myView, params);

对于这个工作,你需要以下权限添加到您的Andr​​oidManifest.xml

For this to work, you will need to add the following permission to your AndroidManifest.xml

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

这篇关于什么是窗口管理器,在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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