国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

35.橫豎屏切換

2019-11-09 16:25:26
字體:
來源:轉載
供稿:網友

安卓模擬器里,用ctrl+f11按鍵來觸發橫豎屏,橫豎屏切換的時候默認會觸發生命周期方法,

在清單文件中配置下面可以,不用去觸發生命周期的方法,下面三種情況發生的時候不會出發生命周期的方法orientation|keyboardHidden|screenSize

android:configChanges="orientation|keyboardHidden|screenSize"keyboardHidden:隱藏鍵盤(軟鍵盤出現會改變屏幕的寬高)

screenSize:屏幕寬高改變

orientation:方向改變的時候

避免橫豎屏切換,寫死,需要在清單文件中對activity配置:

android:screenOrientation="landscape"  //橫屏寫死
android:screenOrientation="portrait"  //豎屏寫死

代碼中橫豎屏寫死的方法:

    PRotected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//鎖屏activity為橫屏        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//鎖定為豎屏        System.out.println("第一個onCreate方法調用");    }

測試橫豎屏切換出發生命周期方法代碼如下:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>MainActivy

package com.ldw.hengshu;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        System.out.println("第一個onCreate方法調用");    }	@Override	protected void onStart(){		super.onStart();		System.out.println("第一個onStart方法調用");	}		@Override	protected void onResume(){		super.onResume();		System.out.println("第一個onResume方法調用");	}		@Override	protected void onPause(){		super.onPause();		System.out.println("第一個onPause方法調用");	}		@Override	protected void onStop(){		super.onStop();		System.out.println("第一個onStop方法調用");	}		@Override	protected void onDestroy(){		super.onDestroy();		System.out.println("第一個onDestroy方法調用");	}		@Override	protected void onRestart(){		super.onRestart();		System.out.println("第一個onRestart方法調用");	}    }橫豎屏切換以前打印如下:

按下ctrl+F11切換橫豎屏

打印如下


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 民勤县| 开原市| 凯里市| 海安县| 清徐县| 杂多县| 英吉沙县| 古浪县| 牡丹江市| 绥宁县| 南川市| 崇文区| 景洪市| 育儿| 论坛| 珠海市| 揭东县| 柳江县| 高碑店市| 于田县| 永城市| 娱乐| 钦州市| 邯郸县| 长兴县| 宣威市| 莲花县| 丽江市| 黔南| 宁海县| 扎赉特旗| 沂源县| 洛宁县| 梓潼县| 绿春县| 天台县| 墨竹工卡县| 酒泉市| 张家港市| 从化市| 榆林市|