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 ...
随机推荐
- duilib开源界面库
官网: https://code.google.com/p/duilib/ 基于:http://www.viksoe.dk/code/windowless1.htm 教程: http://www.cn ...
- [转]Apple iPod, iPhone (2g, 3g), iPad Dock connector pinout
Pin Signal Description Apple pin numbering* 1 GND Ground (-), internally connected with Pin 2 on iPo ...
- Api 和 Spi
目录 背景Java类库中的实例如何实现这种结构?备注 背景返回目录 Java 中区分 Api 和 Spi,通俗的讲:Api 和 Spi 都是相对的概念,他们的差别只在语义上,Api 直接被应用开发人员 ...
- 哞哞快的 C# 高斯模糊实现(续)
昨天刚写了<哞哞快的 C# 高斯模糊实现>,里边提到了用原作者的方法实现对图像快速的高斯模糊处理,说实话,我没看懂,主要是没看懂原理,怎么就“把图片给处理了”,大概是调用了 GDIPlus ...
- Asycn/Await 异步编程初窥
经过两天密集型的学习,翻阅了大量 webpages ,点击了不少重点 blogs,总算基本了解了一些 async/await 搭配使用的入门技巧,总结一下 1. async/await 应该只是语法上 ...
- HTML文档类型
在HMTL5中页面的最顶端代码就是: <!DOCTYPE html> 为何要如此定义.书写呢? 首先引入一个概念:文档类型,英译为:Document type,缩写成:doctype. 文 ...
- winform程序中为无边框窗体手动添加窗体拖动代码
Point oldMousePoint;//记录开始移动窗口前鼠标点下箭头的位置 Point oldFormPoint;//记录开始移动窗口前窗体位置 // ...
- 三种不同实现初始化和销毁bean之前进行的操作的比较
Spring容器中的bean是有生命周期的,Spring 允许在 Bean 在初始化完成后以及 Bean 销毁前执行特定的操作,常用的设定方式有以下三种: 通过实现 InitializingBean/ ...
- TOGAF架构开发方法(ADM)之架构变更管理阶段
TOGAF架构开发方法(ADM)之架构变更管理阶段 1.10 架构变更管理(Architecture Change Management) 企业架构开发方法各阶段——架构变更管理 1.10.1 目标 ...
- hdu 2859 (二维dp)
点击打开链接 题意: 给你一个n*n的矩阵,矩阵中只含有26个小写字母,求其中最大的对称矩阵的大小 当我们算到s[i][j]时,每次我们只需要将它上方的和右方的依次比较,看是否相同 注意这里不能只比较 ...