获取窗口的大小,而不标题/通知栏而不、大小、窗口、标题

2023-09-05 01:51:40 作者:荒年i

我一直在玩弄Android开发及的​​事情,我希望能够做的是动态创建我的窗口,类似下图的背景图像中的一个。

I've been playing around with Android development and one of the things I'd like to be able to do is dynamically create a background image for my windows, similar to the one below.

这是从我的黑莓手机应用程序。它由三个独立的部分,右下徽标,左上方水印,和右下角名称。它的工作原理独立的屏幕尺寸,因为黑莓手机应用程序中使用的屏幕宽度和高度刚刚获得所有三个部分,并产生一个适当大小的位图。

This is from my BlackBerry app. It consists of three separate parts, the bottom right logo, the top left watermark, and the bottom right name. It works independent of screen size because the BlackBerry app just gets all three parts and generates an appropriately sized bitmap using the screen width and height.

由于Android有我需要能够产生对这样的飞行背景相当多的屏幕分辨率的可能性。但是,我还没有找到任何方式来获得在Android上窗口的高度/宽度。我可以在屏幕分辨率,但包括应用程序标题栏和通知栏,这是不可接受的。

Since Android has quite a bit more screen resolution possibilities I need to be able to generate backgrounds on the fly like this. However, I have not found any way to get the height/width of the window in Android. I can get the screen resolution, but that includes the application title bar and the notification bar, which is unacceptable.

我想知道如何让我的窗口的大小,或者屏幕分辨率减去标题和通知栏。我想用我的布局管理器的尺寸,这可能是可能的,但我不能让他们的高度/宽度在onCreate方法,所以我不知道该怎么做完全是。

I'd like to know how to get the size of my window, or screen resolution minus the title and notification bars. I think this might be possible using the dimensions of my layout managers but I cannot get the height/width of them in the onCreate method so I'm not sure what to do exactly.

感谢。

推荐答案

使用View.MeasureSpec.getSize在onMeasure覆盖。

    @Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    ...
}