最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中獲得手機(jī)屏幕大小實(shí)現(xiàn)代碼

 更新時(shí)間:2015年06月09日 11:45:43   投稿:junjie  
這篇文章主要介紹了Android中獲得手機(jī)屏幕大小實(shí)現(xiàn)代碼,Android開(kāi)發(fā)中經(jīng)常需要獲得屏幕的寬高,本文直接封裝成一個(gè)工具類,需要的朋友可以參考下

Android在自定義控件時(shí),經(jīng)常需要獲得屏幕的寬高,每次都要寫(xiě),不妨直接把他封裝成工具類,直接拿來(lái)用,廢話不說(shuō),直接上代碼

/**
 * 
 */
package com.example.customview;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * 獲取手機(jī)屏幕大小
 * @author 
 *
 */
public class MeasureUtil {
 
 /**
 * 寬
 * @return
 */
 public static int getWidth(Context context){
 WindowManager wm=(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
 DisplayMetrics outMetrics = new DisplayMetrics();
 wm.getDefaultDisplay().getMetrics(outMetrics);
 return outMetrics.widthPixels;
 }
 
 /**
 * 高
 * @return
 */
 public static int getHeight(Context context){
 WindowManager wm=(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
 DisplayMetrics outMetrics = new DisplayMetrics();
 wm.getDefaultDisplay().getMetrics(outMetrics);
 return outMetrics.heightPixels;
 }

}

相關(guān)文章

最新評(píng)論

巴青县| 宁陵县| 天柱县| 开阳县| 吴桥县| 阜阳市| 毕节市| 叙永县| 新巴尔虎右旗| 建平县| 巴塘县| 台江县| 瑞昌市| 庄浪县| 和政县| 施甸县| 库尔勒市| 纳雍县| 武义县| 蒙阴县| 民权县| 南通市| 青浦区| 乐都县| 沐川县| 乐业县| 太原市| 静海县| 贺兰县| 怀宁县| 通化市| 湟中县| 洛宁县| 盐山县| 淮阳县| 阿勒泰市| 弋阳县| 襄垣县| 陆川县| 陇南市| 包头市|