码迷,mamicode.com
首页 > 移动开发 > 详细

Android获取窗体信息的Util方法

时间:2015-07-15 20:39:48      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

 1 package com.wangyi.tools;
 2 
 3 import android.app.Activity;
 4 import android.util.DisplayMetrics;
 5 
 6 public class DisplayUtils {
 7     
 8     private static DisplayUtils instance;
 9     private Activity mActivity;
10     private DisplayUtils(Activity mActivity){
11         this.mActivity=mActivity;
12     }
13     public static DisplayUtils getInstance(Activity mActivity){
14         if(instance==null){
15             instance=new DisplayUtils(mActivity);
16         }
17         return instance;
18     }
19     public final  int[] getScreenSize(){
20         int[] size=new int[2];
21         DisplayMetrics dm = new DisplayMetrics();
22         mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
23         size[0]=dm.widthPixels;
24         size[1]=dm.heightPixels;
25         return size;
26     }
27     public final static int getWindowWidth(Activity mActivity) {
28         DisplayMetrics dm = new DisplayMetrics();
29         mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
30         return dm.widthPixels;
31     }
32 
33     public final static int getWindowHeight(Activity mActivity) {
34         DisplayMetrics dm = new DisplayMetrics();
35         mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
36         return dm.heightPixels;
37     }
38 }

 

Android获取窗体信息的Util方法

标签:

原文地址:http://www.cnblogs.com/joyblabla/p/4649209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!