Android WebView:处理方向变化 [英] Android WebView: handling orientation changes

查看:24
本文介绍了Android WebView:处理方向变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是轮换后的性能.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆