android 获取屏幕大小和方向

来源:互联网 发布:java绘制实心五角星 编辑:程序博客网 时间:2024/05/29 21:31
// 屏幕方面切换时获得方向
 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 = newDisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
  int screenWidth =dMetrics.widthPixels;
  int screenHeight =dMetrics.heightPixels;