---
title: "android 获得屏幕宽度 高度"
author: "daoshud1"
date: "2014-08-29T17:00:58Z"
tags: []
categories: ["编程语言"]
slug: "android"
draft: false
lastmod: "2014-08-29T17:00:58Z"
id: 2110855
url: "https://daoshud1.iteye.com/blog/2110855"
---

android获取屏幕的高度和宽度用到WindowManager这个类，两种方法： 

```java

1、WindowManager wm = (WindowManager) getContext()
                    .getSystemService(Context.WINDOW_SERVICE);
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();

```

 

```java

2、WindowManager wm = this.getWindowManager();
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();

```