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

創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、魯山網(wǎng)絡(luò)推廣、成都小程序開發(fā)、魯山網(wǎng)絡(luò)營銷、魯山企業(yè)策劃、魯山品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供魯山建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com
- Android:configChanges="orientation"
同時(shí)在Activity中覆寫onConfigurationChanged方法
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- Log.i("TAG","I'm Android 2.3");
- }
通過設(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)竟然沒有效果,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).
也就是說在Android 3.2(API level 13)以后,當(dāng)設(shè)備橫豎屏切換時(shí)屏幕尺寸也改變了。因此,如果你想在API Level 13或者 更高的環(huán)境下,像以前那樣阻止設(shè)備的橫豎屏切換,你需要在orientation后加上screenSize。也就說你要像這樣聲明:android:configChanges="orientation|screenSize"。
也就是說我們現(xiàn)在要在AndroidManifest.xml中的Activity加入以下屬性:
Android:configChanges="orientation|screenSize"
本文題目:Android橫豎屏切換
URL分享:http://m.fisionsoft.com.cn/article/cciieds.html


咨詢
建站咨詢
