zoukankan      html  css  js  c++  java
  • screen-Orientation 横竖屏设置

    1.xml中设置,这个主要是在AndroidManifest.xml 中查找activity,然后在里面设置属性,如下

    <application android:label="@string/app_name" android:icon="@mipmap/ic_launcher_calculator">
            <activity android:name="Calculator" 
                      android:theme="@style/Calculator.Theme"
                      android:windowSoftInputMode="stateAlwaysHidden"
                     <!--屏幕设定--> 
              android:screenOrientation
    ="portrait" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.APP_CALCULATOR" /> </intent-filter> </activity> </application>

    这个属性android:screenOrientation="portrait"有以下几个属性

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

    2.代码中进行设定

    //设置横屏
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    
    //设置竖屏
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    /*
    因为横屏有两个方向的横法,而这个设置横屏的语句,如果不是默认的横屏方向,会把已经横屏的屏幕旋转180°。
    所以可以先判断是否已经为横屏了,如果不是再旋转,不会让用户觉得转的莫名其妙啦!代码如下:*/
    if(this.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT){
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
  • 相关阅读:
    DC综合流程
    DC set_tcl脚本配置
    同步FIFO设计
    顺序脉冲 发生器
    状态机的写法
    verilog串并转换
    indexOf()
    jQuery 效果
    jQuery 事件
    jQuery css
  • 原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_orientation_150211195.html
Copyright © 2011-2022 走看看