Android获取屏幕宽度高度
方法一:
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
方法二:
WindowManager wm1 = this.getWindowManager();
int width1 = wm1.getDefaultDisplay().getWidth();
int height1 = wm1.getDefaultDisplay().getHeight();
方法一与方法二获取屏幕宽度的方法类似,只是获取WindowManager 对象时的途径不同。
方法三:
WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width2 = outMetrics.widthPixels;
int height2 = outMetrics.heightPixels;
方法四:
Resources resources = this.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
float density1 = dm.density;
int width3 = dm.widthPixels;
int height3 = dm.heightPixels;
方法三与方法四类似。
Android获取屏幕宽度高度的更多相关文章
- Android获取屏幕宽度、高度的4种方法
记录学习之用,有相同的问题可以参考 方法一: WindowManager wm = (WindowManager) this .getSystemService(Context.WINDOW_SERV ...
- Android获取屏幕宽度的4种方法
方法一: WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); int width = w ...
- 【转】android获取屏幕宽度和高度
原文网址:http://www.cnblogs.com/howlaa/p/4123186.html 1. WindowManager wm = (WindowManager) getContext() ...
- android获取屏幕宽度和高度
1. WindowManager wm = (WindowManager) getContext() .getSystemService(Context.WINDOW_SERVICE); int wi ...
- android 获取屏幕宽度和高度
// 获取屏幕宽高(方法1) int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); // 屏幕宽(像素,如:480p ...
- Android获取屏幕高度、标题高度、状态栏高度详解
Android获取屏幕高度的方法主要由view提供 通过View提供的方法获取高度方式有两种: 1, 当前显示的view中直接获取当前view高宽2,通过Activity的getWindow().fi ...
- 微信小程序如何获取屏幕宽度
微信小程序如何获取屏幕宽度 方法1: imageLoad: function () { this.setData({ imageWidth: wx.getSystemInfoSync().window ...
- 微信小程序(6)--获取屏幕宽度及弹窗滚动与页面滚动冲突
1.获取屏幕宽度,并赋值给view <view class="ships-img" style="height:{{windowWidth}}px;"&g ...
- android Xml生成一条细线,以及获取屏幕宽度和高度
<View android:layout_width="match_parent" android:layout_height="2dip" androi ...
随机推荐
- SQL Check
一款实时性能监测工具 SQL Check? 一款实时监测SQL数据库性能.实时排查的问题的免费工具. 可以实时监测20个左右的SQL关键性能指标,每个指标都已图形化动态直播形式展现. 适合DBA.数据 ...
- [LeetCode] Symmetric Tree 判断对称树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- 关于Django 错误 doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
记录一下 报错 doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS\ 这个问题出现没 ...
- [webpack] 配置react+es6开发环境
写在前面 每次开新项目都要重新安装需要的包,简单记录一下. 以下仅包含最简单的功能: 编译react 编译es6 打包src中入口文件index.js至dist webpack配置react+es6开 ...
- cocos2d-x事件EventListenerTouchOneByOne没反应
今天写了 cocos2d-x事件EventListenerTouchOneByOne,发现死活没反应,原代码复制到新工程没问题啊, 后来发现cocostudio用的基础容器(ccui.Layout:c ...
- css学习笔记(2)
----------------|-------------------------|------------------ 标签名 英文全拼 中文 ...
- 【转】OpenGL多线程创建纹理,附加我的测试结果
原文地址 http://www.cnblogs.com/mazhenyu/archive/2010/04/29/1724190.html 关于这个问题以前只知道多个线程不能同时使用一个RC,结果为了能 ...
- 格式工厂 v4.0.0 最新去广告绿色纯净版
最好用的多媒体格式转换利器:格式工厂现已更新至v4.0,此次更新加入最新的HEVC(H265)编码,MP4,MKV的压缩比大幅度提高!格式工厂,轻松转换一切你想要的格式!利器在手,转换不愁! 格式工厂 ...
- phpcms二次开发中无法获取SESSION的值
今天在在phpcms开发留言板用到验证码,提交数据,后台无法$_SESSION['code']无法获取验证码值,也无法打印var_dump($_SESSION)值,我们只需要在文件头部添加如下代码: ...
- 初次认识 C# win32 api
第一次接触win32api,刚开始的时候有点迷迷糊糊的. Windows API 就是windows应用程序接口. win api向上就是windows应用程序,向下就是windows操作系统核心. ...