Android 关于屏幕横竖屏 你所知道的一切

来源:互联网 发布:windows.old还原 编辑:程序博客网 时间:2024/05/16 15:35

package com.example.demo22;import android.os.Bundle;import android.app.Activity;import android.content.res.Configuration;import android.util.Log;import android.view.Menu;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Log.i("---", "onCreate");}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();Log.i("---", "onDestroy");}@Overrideprotected void onPause() {// TODO Auto-generated method stubsuper.onPause();Log.i("---", "onPause");}@Overrideprotected void onRestart() {// TODO Auto-generated method stubsuper.onRestart();Log.i("---", "onRestart");}@Overrideprotected void onRestoreInstanceState(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onRestoreInstanceState(savedInstanceState);Log.i("---", "onRestoreInstanceState");}@Overrideprotected void onResume() {// TODO Auto-generated method stubsuper.onResume();Log.i("---", "onResume");}@Overrideprotected void onSaveInstanceState(Bundle outState) {// TODO Auto-generated method stubsuper.onSaveInstanceState(outState);Log.i("---", "onSaveInstanceState");}@Overrideprotected void onStart() {// TODO Auto-generated method stubsuper.onStart();Log.i("---", "onStart");}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();Log.i("---", "onStop");}@Overridepublic void onConfigurationChanged(Configuration newConfig) {// TODO Auto-generated method stubsuper.onConfigurationChanged(newConfig);Log.i("---", "onConfigurationChanged");}}


首先 每个手机都可以设置横竖屏锁定

        当手机设置 无横竖屏锁定时:

        1、activity 默认不设置时:

                 

        <activity            android:name="com.example.demo22.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>
              手机竖-》横

              

    横-》竖


当设置为android:screenOrientation="portrait"时

activity 为竖屏 手机横屏没反应

当设置android:screenOrientation="landscape"

activity 为横屏 竖屏没反应


android:configChanges="orientation|keyboardHidden"

和 设置成

android:configChanges="orientation"

手机横竖屏切换和上面一样 我也不知道怎么回事 和 网上我博客不一样  

备注 我用的真机 

我的 manifest如下



时隔两天我知道了为什么我的真机没有出现应该出现的这个情况


   是因为我设置的是android:configChanges="orientation|keyboardHidden"

其实应该是android:configChanges="orientation|keyboardHidden|screenSize"

问题出在 screenSize的参数上

查了些资料 

Andorid 3.2以前的SDK可以使用如下配置

android:configChanges="orientation|keyboardHidden"

而Adnroid 3.2以后的SDK必须添加一个screenSize属性,

具体如下android:configChanges="keyboardHidden|orientation|screenSize"或者android:configChanges="orientation|screenSize"

事情终于圆满解决 不过网上说的横切

0 0