• 禁止横屏和竖屏切换


    在某些场合可能需要禁止横屏和竖屏切换,实现这个要求很简单,只要在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>

  • 相关阅读:
    js实现截图并下载到本地
    div里面的文本内容居中显示
    div里面的p标签内容上下垂直居中
    《将博客搬至CSDN》
    RobotFramework 用例出错后继续操作
    selenium+log4j+eclipse相关问题及解决方案
    linux 安装maven
    LINUX下查看系统参数的常见命令
    Linux常用命令使用
    grep 命令
  • 原文地址:https://www.cnblogs.com/huanglong/p/2118427.html
Copyright © 2020-2023  润新知