Android WebView:处理方向更改 [英] Android WebView: handling orientation changes
问题描述
问题是轮换后的性能. WebView必须重新加载页面,这可能有点乏味.
The issue is the performance following rotation. The WebView has to reload the page, which can be a bit tedious.
在不每次都从源头重新加载页面的情况下,处理方向变化的最佳方法是什么?
What's the best way of handling an orientation change without reloading the page from source each time?
推荐答案
如果您不希望WebView在方向更改时重新加载,只需在Activity类中重写onConfigurationChanged即可:
If you do not want the WebView to reload on orientation changes simply override onConfigurationChanged in your Activity class:
@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
并在清单中设置android:configChanges属性:
And set the android:configChanges attribute in the manifest:
<activity android:name="..."
android:label="@string/appName"
android:configChanges="orientation|screenSize"
有关更多信息,请参见:
http://developer.android.com/guide/topics/resources /runtime-changes.html#HandlingTheChange
for more info see:
http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange
https://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges
这篇关于Android WebView:处理方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!