自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android橫豎屏切換

移動(dòng)開(kāi)發(fā) Android
在Android 2.3平臺(tái)上,我們可以需要設(shè)置界面的橫豎屏顯示時(shí),可以在AndroidManifest.xml中,同時(shí)在Activity中覆寫(xiě)onConfigurationChanged方法,通過(guò)設(shè)置,當(dāng)前Activity在橫豎屏切換的時(shí)候,便不會(huì)重新走Activity的生命周期,而是直接執(zhí)行onConfigurationChanged()方法里的內(nèi)容。在Android 4.0上,API level 13以后Android做了修改,橫豎屏切換時(shí)屏幕尺寸改變了。

Android 2.3以前的橫豎屏切換:

在Android 2.3平臺(tái)上,我們可以需要設(shè)置界面的橫豎屏顯示時(shí),可以在AndroidManifest.xml中,對(duì)Activity的屬性添加以下代碼:

  1. Android:configChanges="orientation" 

同時(shí)在Activity中覆寫(xiě)onConfigurationChanged方法

  1. @Override 
  2. public void onConfigurationChanged(Configuration newConfig) { 
  3. super.onConfigurationChanged(newConfig); 
  4. Log.i("TAG","I'm Android 2.3"); 

通過(guò)設(shè)置,當(dāng)前Activity在橫豎屏切換的時(shí)候,便不會(huì)重新走Activity的生命周期,而是直接執(zhí)行onConfigurationChanged()方法里的內(nèi)容。

Android 4.0以后的橫豎屏切換:

當(dāng)我們?cè)贏ndroid 4.0上像之前那樣設(shè)置橫豎屏?xí)r,會(huì)發(fā)現(xiàn)竟然沒(méi)有效果,Activity依然走自己的生命周期,這是因?yàn)樵贏PI level 13以后Android做了修改了,SDK描述如下:

 

Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. 

Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), 

you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". 

However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

 

也就是說(shuō)在Android 3.2(API level 13)以后,當(dāng)設(shè)備橫豎屏切換時(shí)屏幕尺寸也改變了。因此,如果你想在API Level 13或者 更高的環(huán)境下,像以前那樣阻止設(shè)備的橫豎屏切換,你需要在orientation后加上screenSize。也就說(shuō)你要像這樣聲明:android:configChanges="orientation|screenSize"。

也就是說(shuō)我們現(xiàn)在要在AndroidManifest.xml中的Activity加入以下屬性:

Android:configChanges="orientation|screenSize"

責(zé)任編輯:閆佳明 來(lái)源: oschina
相關(guān)推薦

2010-01-25 15:23:12

Android橫豎屏切

2011-07-29 10:21:03

iPad 橫豎屏 切換

2011-06-08 15:05:43

J2ME

2013-08-21 11:15:54

iOS橫豎屏方案

2017-07-25 09:55:10

iOS橫豎屏旋轉(zhuǎn)

2012-05-22 14:26:15

XNA 橫豎屏設(shè)置

2016-09-18 10:51:01

JavascriptHtml5移動(dòng)應(yīng)用

2021-06-28 14:41:36

鴻蒙HarmonyOS應(yīng)用

2012-07-16 10:09:39

Windows 7操作系統(tǒng)

2023-06-29 08:41:34

Android“短暫”模式

2009-07-07 08:44:52

微軟Windows 7新功能

2010-01-28 17:12:45

Android閃屏

2011-09-07 10:44:05

Android Wid

2013-07-29 05:04:19

Cocos2dx橫屏豎

2012-02-28 14:07:17

Android觸摸屏手勢(shì)識(shí)別

2017-01-11 18:36:04

Android矩形區(qū)域截屏移動(dòng)開(kāi)發(fā)

2010-09-10 10:09:26

Android

2020-05-27 15:39:06

安卓Android手機(jī)

2011-05-25 17:34:16

Android

2015-03-24 10:51:46

Android鎖屏
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)