在 android 中更改方向时重新创建 WebView

发布于 2024-12-26 02:20:00 字数 312 浏览 3 评论 0原文

我已经构建了一个应用程序,最好的部分是,它运行良好,最糟糕的部分是,每当我握住设备并将其从纵向变为横向或反之亦然时,每次方向改变时视图都会重新生成。我已经尽我所知完成了所有可能的事情,即

1.创建了 layout-land 文件夹并放置了横向模式的 xml 文件。
2.已在清单中给予以下许可:

 android:configChanges="orientation|keyboardHidden"

还有其他我遗漏的内容吗?

我不希望每当我改变方向时都会发生变化或娱乐。

I have built an application and the best part is, it is running fine and the worst part is,whenever I hold the device and turn it from portrait to landscape or vice versa,the views are regenerating each and every time when the orientation changes.I have done all the possible things to the best of my knowledge i.e.

1.created layout-land folder and placed the xml file for the landscape mode.
2.Have given the following permission in the manifest:

 android:configChanges="orientation|keyboardHidden"

Is there anything else I have missed out?

I do not want the changes or recreation to occur whenever I change the orientation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小墨 2025-01-02 02:20:00

默认情况下,当方向更改时,会重新创建 Android Activity,默认情况下使用的 xml 布局是“layout”文件夹中的 xml,除非“layout-land”中有一个用于横向模式的单独 xml。

另一方面,如果您想自行处理方向或任何其他配置更改并避免调用 OnCreate(),则在清单文件中使用“android:configChanges”并在您的活动中覆盖 OnConfigChanges。

By default,Android activity is recreated when orientation is changed, and xml layout used by default is xml that you have in "layout" folder unless you have a separate xml in "layout-land" for landscape mode.

On the other hand if you want to handle Orientation or any other config changes by you self and to avoid calling OnCreate() then use "android:configChanges" in manifest file and Overide OnConfigChanges in your activity.

蓝眼睛不忧郁 2025-01-02 02:20:00

它重新创建您的视图的原因是因为 oncreate 正在被调用。理想情况下,这将重置您的所有视图。如果您重写处理方向更改的方法,您将更容易捕获它并保留您的视图。

前任:
http://jnastase.alner.net /archive/2010/10/27/handling-orientation-change-in-android.aspx

The reason that it is recreating your views is because the oncreate is being called. This will ideally reset all your views. If you override the method that handles the orientation changes, you will catch it a lot easier and preserve your views.

Ex:
http://jnastase.alner.net/archive/2010/10/27/handling-orientation-change-in-android.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文