获得android手机屏幕的宽高的类

来源:互联网 发布:rup软件过程模型 编辑:程序博客网 时间:2024/06/12 04:11

public class WindowHelper {private static int sWindowHeight;private static int sWindowWidth;public static int getWindowHeight() {return sWindowHeight;}public static int getWindowWidth() {return sWindowWidth;}public static void initWindowWH(Context paramContext) {WindowManager localWindowManager = (WindowManager) paramContext.getSystemService("window");DisplayMetrics localDisplayMetrics = new DisplayMetrics();localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics);sWindowWidth = localDisplayMetrics.widthPixels;sWindowHeight = localDisplayMetrics.heightPixels;}}

调用时:

WindowHelper.initWindowWH(MainActivity.this);System.out.println("h------" + WindowHelper.getWindowHeight());System.out.println("w------" + WindowHelper.getWindowWidth());
OK>>>>>>>>>>

0 0