android设置全屏和横屏

小鱼儿 2022-07-27 14:35 323阅读 0赞

转载地址:http://daikainan.iteye.com/blog/1405649

横屏设置

XML文件设置—portrait为纵向,landscape为横向

android:screenOrientation=”portrait”

android:screenOrientation=[“unspecified” | “user” | “behind” |
“landscape” | “portrait” |
“sensor” | “nonsensor”]

screenOrientation 用来指定Activity的在设备上显示的方向,每个值代表如下含义:
“unspecified” 默认值 由系统来判断显示方向.判定的策略是和设备相关的,所以不同的设备会有不同的显示方向.
“landscape” 横屏显示(宽比高要长)
“portrait” 竖屏显示(高比宽要长)
“user” 用户当前首选的方向
“behind” 和该Activity下面的那个Activity的方向一致(在Activity堆栈中的)
“sensor” 有物理的感应器来决定。如果用户旋转设备这屏幕会横竖屏切换。
“nosensor” 忽略物理感应器,这样就不会随着用户旋转设备而更改了 ( “unspecified”设置除外 )。

代码设置

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

全屏两种方法:
方法一:

Java代码 收藏代码

  1. public void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. //设置无标题
  4. requestWindowFeature(Window.FEATURE_NO_TITLE);
  5. //设置全屏
  6. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  7. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  8. setContentView(R.layout.main);
  9. }

方法二:

Xml代码 收藏代码

  1. <?**xml version=”1.0” encoding=”utf-8”?>**
  2. <**manifest** xmlns:android=”http://schemas.android.com/apk/res/android“
  3. package=”com.andyidea”
  4. android:versionCode=”1”
  5. android:versionName=”1.0” >
  6. <**uses-sdk android:minSdkVersion=”8” />**
  7. <**application**
  8. android:icon=”@drawable/icon”
  9. android:label=”@string/app_name” >
  10. <**activity**
  11. android:name=”.login.LoginActivity”
  12. android:label=”@string/app_name”
  13. android:theme=”@android:style/android.NoTitleBar.Fullscreen” >
  14. <**intent-filter**>
  15. <**action android:name=”android.intent.action.MAIN” />**
  16. <**category android:name=”android.intent.category.LAUNCHER” />**
  17. </**intent-filter**>
  18. </**activity**>
  19. </**application**>
  20. </**manifest**>

发表评论

表情:
评论列表 (有 0 条评论,323人围观)

还没有评论,来说两句吧...

相关阅读