Android获得屏幕大小和方向

// 屏幕方面切换时获得方向
  if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
   setTitle("landscape");
  }
  if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
   setTitle("portrait");
  }
  // 获得屏幕大小1
  WindowManager manager = getWindowManager();
  int width = manager.getDefaultDisplay().getWidth();
  int height = manager.getDefaultDisplay().getHeight();
  // 获得屏幕大小2
  DisplayMetrics dMetrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
  int screenWidth = dMetrics.widthPixels;
  int screenHeight = dMetrics.heightPixels;

posted @ 2013-01-24 17:01  bavariama  阅读(220)  评论(0编辑  收藏  举报