如何获取设备的最大宽度和高度的机器人宽度、机器人、高度、设备

2023-09-07 12:01:57 作者:让我堕落

您好我有创造一个Android应用程序的自定义视图的问题。我的自定义视图要使用,如果允许的最大屏幕宽度。我找不到任何方法来检索此值。

Hi I have a problem creating a custom view for an Android application. My custom view wants to use if permitted the maximum screen width. I couldn't find any way to retrieve this value.

任何人都可以点我正确的方法?

Can anybody point me to the right method?

推荐答案

尝试

mWinMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
int displayWidth = mWinMgr.getDefaultDisplay().getWidth();

其中,背景是上下文实例。

默认情况下,的FrameLayout 中,你的布局保持,覆盖整个显示器水平(垂直方向可以有状态栏)。所以,你可以通过设置最大可能的宽度 Android的:layout_width =FILL_PARENT正确

By default, the FrameLayout in which your layout is kept, fills the whole display horizontally (vertically you can have status bar). So you can set the maximum possible width by using android:layout_width="fill_parent" correctly.