android获得屏幕高度和宽度(display中getSize(Point)方法使用)
方法一:
public static int SCREEN_WIDTH;
public static int SCREEN_HEIGHT;
//获取屏幕
WindowManager wm = (WindowManager) getBaseContext().getSystemService(
Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
SCREEN_WIDTH= size.x;
SCREEN_HEIGHT= size.y;
display中getSize(Point)方法使用:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth(); // deprecated
int height = display.getHeight(); // deprecated
查看API 发现:
int getWidth()、int getHeight()方法:(我用的是level 19)
This method was deprecated in API level 13. Use getSize(Point) instead.
在看一下getSize(Point)方法:
public void getSize (Point outSize)
Gets the size of the display, in pixels.
Note that this value should not be used for computing layouts, since a device will typically have screen decoration (such as a status bar) along the edges of the display that reduce the amount of application space available from the size returned here. Layouts should instead use the window size.
The size is adjusted based on the current rotation of the display.
The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decoration elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays
Parameters
| outSize | A Point object to receive the size information. |
|---|
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
diswidth = getContext().getResources().getDisplayMetrics().widthPixels;
disheight = getContext().getResources().getDisplayMetrics().heightPixels;
android获得屏幕高度和宽度(display中getSize(Point)方法使用)的更多相关文章
- android获得屏幕高度和宽度
获取屏幕的宽度与高度有以下几种方法: .WindowManager wm = (WindowManager) getContext() .getSystemSe ...
- 【笔记】css 实现宽度自适应屏幕 高度自适应宽度
如果说宽高自适应屏幕尺寸那么大家可能会想到 div{ width: 100%; height: 100% } 但是如果我要自适应屏幕尺寸的同时还要变成正方形呢?(高度和宽度相等而高度不能写死) 那就要 ...
- JavaScript浏览器对象(BOM)中有关设备、浏览器屏幕高度和宽度的API介绍
JavaScript世界中,有很多看起来能够帮我们知道网页宽度和高度的API,但太繁多了,而且容易弄混.不容易区分它们.下面我就来介绍一下,这些API到底是什么意思,之间的区别又在哪里. 一.设备的分 ...
- css设置div高度与宽度相等的一种方法
div.category{ width:33%; padding:33% 0 0; } 1.关键在padding:33% 0 0这句代码,通过设置padding-top与宽度相等(padding使用百 ...
- 网页或微信小程序中使元素占满整个屏幕高度
在项目中经常要用到一个容器元素占满屏幕高度和宽度,然后再在这个容器元素里放置其他元素. 宽度很简单就是width:100% 但是高度呢,我们知道的是height:100%必须是在父元素的高度给定了的情 ...
- Android 关于屏幕适配
android屏幕适配详解 官方地址:http://developer.android.com/guide/practices/screens_support.html 转自:http://www.c ...
- 获取Android状态栏的高度
Android 开发中经常需要知道屏幕高度.宽度.状态栏,标题栏的高度等 宽度和高度 WindowManager windowManager = (WindowManager) getSystemSe ...
- android 获取屏幕的高度和宽度、获取控件在屏幕中的位置、获取屏幕中控件的高度和宽度
(一)获取屏幕的高度和宽度 有两种方法: 方法1: WindowManager wm = (WindowManager) getContext().getSystemService(Context.W ...
- Android 修改toast的默认位置和获取当前屏幕的高度和宽度
Toast toast; toast=Toast.makeText(this, "toast", Toast.LENGTH_LONG); toast.setGravity(grav ...
随机推荐
- AutoPostBack通过现象看本质
在做人事档案管理系统时遇到一个功能需要实现前台数据(实时)与后台进行交互,解决这个问题首先想到的是应用控件的AutoPostBack属性.本以为这个问题就这样解决了(不用javascript.jque ...
- 使用with ties查询并列的数据
select top 1 with ties name,stuId,sex,score from stuInfo order by score desc
- HtmlParser的使用-爬虫学习(三)
关于这个HtmlParser的学习资料,网上真的很匮乏,这个好用的东西不要浪费啊,所以我在这里隆重的介绍一下. HtmlParser是一个用来解析HTML文件的Java包,主要用于转换盒抽取两个方面. ...
- Django 源码小剖: 初探 WSGI
Django 源码小剖: 初探 WSGI python 作为一种脚本语言, 已经逐渐大量用于 web 后台开发中, 而基于 python 的 web 应用程序框架也越来越多, Bottle, Djan ...
- java正则表达式验证汉字
统计指定内容的汉字个数: String str = "北京欢迎你 hello welcome!"; int count=0; Pattern pattern = Pattern.c ...
- andoid x项目的优化 1
通常我们写程序,都是在项目计划的压力下完成的,此时完成的代码可以完成具体业务逻辑,但是性能不一定是最优化的,一般来说,一般来说,优秀的程序员在写完代码之后都会不断的对代码进行重构.重构的好处有很多,其 ...
- 捕鱼达人代码例子下载地址 Win版
捕鱼达人代码例子下载地址 Win版:: http://pan.baidu.com/share/link?shareid=1601576904&uk=3189484501
- Android——另外一种增删查改的方式(ContentProvider常用)
以下介绍另外一种增删查改的方式 package com.njupt.sqllist; import java.util.ArrayList; import java.util.List; import ...
- Laravel5.3 流程粗粒度分析之bootstrap
从laravel入口文件index里面外面不难定位到Illuminate\Foundation\Http\Kernel的handle方法,同样也不难发现handle方法的核心是 $response = ...
- JSP引擎的工作原理
JSP运行环境: 执行JSP代码需要在服务器上安装JSP引擎,比较常见的引擎有WebLogic和Tomcat.把这些支持JSP的web服务器配置好后.就可以再客户端通过浏览器来访问JSP页面了.默认端 ...