在Activity中判断横竖屏的切换

来源:互联网 发布:黑猫影视软件 编辑:程序博客网 时间:2024/05/17 23:21
        在继承了Activity的类中,可以通过重写onConfigurationChanged方法来判断屏幕的朝向

        @Overridepublic void onConfigurationChanged(Configuration newConfig) {super.onConfigurationChanged(newConfig);if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 加入横屏要处理的代码} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {// 加入竖屏要处理的代码}}


在Manifest.xml文件中注册Activity的信息:

< activity android:name="MyActivity"    android:configChanges="orientation|keyboardHidden"> 


0 0
原创粉丝点击