/* First, get the Display from the WindowManager */

  Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

  /* Now we can retrieve all display-related infos */

  int width = display.getWidth();

  int height = display.getHeight();

  int orientation = display.getOrientation();

  或者

  public int getScreenOrientation()

  {

  Display getOrient = getWindowManager().getDefaultDisplay();

  int orientation = getOrient.getOrientation();

  // Sometimes you may get undefined orientation Value is 0

  // simple logic solves the problem compare the screen

  // X,Y Co-ordinates and determine the Orientation in such cases

  if(orientation==Configuration.ORIENTATION_UNDEFINED){

  Configuration config = getResources().getConfiguration();

  orientation = config.orientation;

  if(orientation==Configuration.ORIENTATION_UNDEFINED){

  //if height and widht of screen are equal then

  // it is square orientation

  if(getOrient.getWidth()==getOrient.getHeight()){

  orientation = Configuration.ORIENTATION_SQUARE;

  }else{ //if widht is less than height than it is portrait

  if(getOrient.getWidth() < getOrient.getHeight()){

  orientation = Configuration.ORIENTATION_PORTRAIT;

  }else{ // if it is not any of the above it will defineitly be landscape

  orientation = Configuration.ORIENTATION_LANDSCAPE;

  }

  }

  }

  }

  return orientation; // return value 1 is portrait and 2 is Landscape Mode

  }

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android 发布应用到市场
  2. 【极客青年】电脑专用的安卓系统-凤凰系
  3. 使用Git之后出现android library引用失败
  4. android之获取设备唯一标识符
  5. android UI进阶之android中隐藏的layout
  6. 文章:开发者眼中的Android手机平台
  7. Android中的WebView进行直接加载网页
  8. Android中的任务和进程详解
  9. Android – 專案的建立與結構
  10. android 自定义menu及 Error parsing XML