在android应用开发过程中,尤其是在界面布局当中,经常会碰到要指定布局为横屏或是竖屏显示,下面是一些设置android横竖屏的方法:
  1. 代码控制
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置成全屏模式setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//强制为横屏setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
  2. xml控制
    在activity里设置android:screenOrientation的值。
    android:screenOrientation的属性有以下值:
    unspecified(默认值,由系统判断状态自动切换),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
    landscape,横屏
    portrait,竖屏
    user(用户当前设置的orientation值),The user's current preferred orientation.
    behind(下一个要显示的Activity的orientation值),The same orientation as the activity that's immediately beneath it in the activity stack.
    sensor(传感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.
    nosensor(不使用传感器,这个效果差不多等于unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.


更多相关文章

  1. Android中的界面布局之帧布局,相对布局
  2. 学习Android从0开始之基础篇(3)-视图组件之布局管理器
  3. Android 五大布局FrameLayout,LinearLayout ,AbsoluteLayout...
  4. Android的CheckBox控件的点击效果布局文件
  5. Android开发UI布局必备基础知识
  6. Android基础入门教程——2.2.1 LinearLayout(线性布局)

随机推荐

  1. Android AMR格式录音和播放,仿微信
  2. Android图形处理-Drawabble
  3. Android studio 028 获取GPS
  4. Android Drawable工具类,
  5. 删除安卓系统的应用
  6. Android 监听长时单击(OnLongClickListene
  7. Android Intent and Intent Filter
  8. Android ApiDemos示例解析(148):Views->L
  9. android之隐式intent调用
  10. android通过自定义toast实现悬浮通知效果