当前位置: 代码迷 >> Android >> android-取得屏幕大小和方向
  详细解决方案

android-取得屏幕大小和方向

热度:70   发布时间:2016-05-01 15:52:35.0
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;

  相关解决方案