如何获取设备的最大宽度和高度的机器人 [英] How do I get a device's maximal width and height in android

查看:124
本文介绍了如何获取设备的最大宽度和高度的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有创造一个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.

这篇关于如何获取设备的最大宽度和高度的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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