zoukankan      html  css  js  c++  java
  • 禁止横屏和竖屏切换

    在某些场合可能需要禁止横屏和竖屏切换,实现这个要求很简单,只要在AndroidManifest.xml里面加入这一行android :screenOrientation="landscape "(landscape 是横向,portrait 是纵向)。不过android中每次屏幕的切换动会重启Activity,所以应该在Activity销毁前保存当前活动的状态,在Activity再次Create的时候载入配置。在activity加上android:configChanges="keyboardHidden|orientation"属性,就不会重启activity.而是去调用onConfigurationChanged(Configuration newConfig). 这样就可以在这个方法里调整显示方式.

    Java代码
    @Override  

        public void onConfigurationChanged(Configuration newConfig) {   

            try {   

                super.onConfigurationChanged(newConfig);   

                if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {   

                    // land   

                } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {   

                   // port   

                }   

            } catch (Exception ex) {   

         }   

        }  

    上面是我找的资料,上面的操作做完了可以实现屏幕的横竖屏切换 不重新启动Activity 并且可以在方法中对横竖屏进行操作

    我一般采取的方式是在AndroidManifest.xml中的显示的Activity中调整,红色字部分添加后实现手机屏幕的固定显示,设置为横屏就一直是横屏,设置为竖屏就一直是竖屏不会随着你手机的颠倒而改变,个人觉的挺好用的。

    <application android:icon="@drawable/icon" android:label="@string/app_name">
      <activity android:name="QRCodeActivity" android:label="@string/app_name"
      android:screenOrientation="landscape" >
       <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
      </activity>

     </application>

  • 相关阅读:
    C++ 如何判断所调用的重载函数
    C++ 入门5 类和动态内存分配(一)
    c#动态创建ODBC数据源
    设为首页,加入收藏,联系我们
    ASP.NET 2.0中CSS失效
    typedef的四个用途和两个陷阱(转)
    VC++实现应用程序对插件的支持(转)
    DOM无关事件
    How to Migrate from WCF Web API to ASP.NET Web API
    Using ASP.NET Web API with ASP.NET Web Forms
  • 原文地址:https://www.cnblogs.com/huanglong/p/2118427.html
Copyright © 2011-2022 走看看