android 手機螢幕翻轉 Activity 介面不更新
雖然用WebView可以顯示網頁,但是當手機翻轉後,他會重新再載入一次網頁,每翻轉一次就重新loading,使用者不舒服,service也會多負擔。
參考自:
官方:https://developer.android.com/guide/topics/resources/runtime-changes.html?hl=zh-tw
網誌:http://blog.csdn.net/chenzheng_java/article/details/6252162
在 AndroidManifest.xml 加入
<manifest>
<application>
<activity
...
android:name=".MainActivity"
...
android:configchanges="orientation|keyboardhidden|screensize">
↑ 加入這行 ↑
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity >
...
</application>
</manifest>
從 Android 3.2 (API 13) 開始,螢幕翻轉螢幕尺寸也會跟著改變,所以要再加上 screenSize在 Activity 中加入
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// 什麼都不用寫
} else {
// 什麼都不用寫
}
}
參考自:
官方:https://developer.android.com/guide/topics/resources/runtime-changes.html?hl=zh-tw
網誌:http://blog.csdn.net/chenzheng_java/article/details/6252162
留言
張貼留言