- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 WindowManager 将布局显示为叠加层时遇到问题。该布局仅覆盖足够的区域以显示其 subview 覆盖的最小区域,而不是覆盖整个屏幕。
我使用以下代码通过 WindowManager 显示布局:
LinearLayout linearLayout = new LinearLayout(MainActivity.this);
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View inflatedLayout = inflater.inflate(R.layout.note_taking_layout, null, false);
linearLayout.addView(inflatedLayout);
final WindowManager.LayoutParams paramsForOverlay = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, // this allows it to show over lock screen AND be able to receive touch.
FLAG_TRANSLUCENT_STATUS | FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
paramsForOverlay.gravity = Gravity.TOP | Gravity.CENTER;
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(new DisplayMetrics());
if (windowManager != null) {
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
windowManager.addView(linearLayout, paramsForOverlay);
}
这是 R.layout.note_taking_layout 的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/llCanvas"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:text="ABCD"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="0dp">
<TextView
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="world" />
<Button
android:id="@+id/bDestroy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello" />
</LinearLayout>
它应该是这样的:
这是它实际的样子:
我该怎么做才能让它覆盖整个屏幕?
编辑:我显示一个按钮并使用此将其扩展到全屏:
final Button button = new Button(MainActivity.this);
button.setText("tis a button");
button.setLayoutParams(
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
最佳答案
经过反复试验,我发现我没有将 MATCH_PARENT 设置为 View inflatedLayout。所以不是这个:
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View inflatedLayout = inflater.inflate(R.layout.note_taking_layout, null, false);
linearLayout.addView(inflatedLayout);
我应该这样做:
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View inflatedLayout = inflater.inflate(R.layout.note_taking_layout, null, false);
inflatedLayout.setLayoutParams( // THIS!
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
linearLayout.addView(inflatedLayout);
关于java - WindowManager addView() 不尊重 MATCH_PARENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49707529/
我使用 WindowManager 添加了一个 View 。 它正确地显示了我想做的事情, 但我有一个问题。 这就是问题。 后退键不影响在android组件下(如事件) 我想要的是我添加的 View
I have drawn an overlay using WindowManager. it's width and height are WindowManager.LayoutParams.MA
我正在开发一个锁屏应用程序,我在服务中使用 WindowManager 添加一个 View 。我已经在 list 文件中为所有 Activity 设置了 Orientation PORTRAIT,但这
我在服务中有一个 WindowManger,我添加了一些标志: params = new WindowManager.LayoutParams( WindowManager.LayoutPar
这是我的代码: params = new WindowManager.LayoutParams( WindowManager.LayoutParams.FLAG_FULLSCREEN,
出于某种原因,我不断收到错误膨胀类消息,因为我正在尝试实现 引起:java.lang.NullPointerException 在 pap.crowslanding.GameView.(GameVie
我正在将 WPF 与当前最新、最好的版本 Caliburn.Micro (1.4.1) 一起使用。我用IWindowManager.ShowWindow(...)打开一个新的无模式窗口: privat
我正在尝试使用 WindowManager 覆盖屏幕,它运行良好,但覆盖屏幕不会覆盖页脚,而是覆盖标题。 这是我的代码。 wm = (WindowManager) getSystemService(C
我使用 wordpress,目前正在为 tinymce-editor 编写一个插件。我使用 windowmanager.open() 函数来显示一个模态,但是我不知道如何在这个模态中隐藏 ok 按钮。
我正在使用此代码通过调暗来更改 Activity 的亮度。 WindowManager.LayoutParams layoutParameters = getWindow().getAttribute
我对由 windowmanager 提供支持的 float 窗口有疑问。它停在屏幕边界处,但我希望它通过。 void startF(int x, int y) { removePopup();
我正在尝试使用 windowManager.open({...}) 创建一个模态窗口,它将有一个(可能很长)项目列表。确保它正确显示的唯一方法是将固定高度设置为模态并使其内容可滚动。 Document
WindowManager.removeViewImmediate() 的文档包含警告(强调我的): Special variation of ViewManager.removeView(View)
我有一个服务。我已经使用 WindowManager 在服务运行期间显示一些 UI。此外,我在此服务的生命周期内显示通知。 下面是我的服务类 public class DemoService exte
我(我希望)在为 Google TV 进行一些开发时遇到了一些小问题 我想要做的是我希望能够在右下角显示一个小窗口,这很好..问题是我不确定如何摆脱后台的屏幕保护程序 这是我目前的代码。 pu
显示在屏幕上的窗口 public class FlatingViewService extends Service{ public static WindowManager windowM
我已经针对同一问题查找了几个帖子,但似乎无法解决我的问题。我在整个应用程序中都使用了微调器,它们运行良好。当我尝试在弹出窗口中使用微调器时,选择它时出现错误。弹出窗口用于添加引用,我已经声明了一个全局
我的应用程序在特定时间向用户显示一个按钮作为 TYPE_SYSTEM_ALERT,我试图让用户 move 它。触摸和 move Action 确实使用以下代码注册,但按钮不会 move 。我错过了什么
有人可以在下面详细解释一下吗, 1- What is the use of ActivityManager & WindowManager? 2- What is the difference bet
我正在开发用于背景视频录制 的应用程序,这就是我使用 WindowManager 的原因,但它对我不起作用。出现以下错误: 08-23 15:38:21.021: E/AndroidRuntime(4
我是一名优秀的程序员,十分优秀!