Android 方向改变时视图重新创建

发布于 2024-12-18 11:52:11 字数 63 浏览 2 评论 0原文

我想做一些类似于 iPhone 开发的事情:手动重新定位控件而不重新创建整个视图。 这种方法的优点和缺点是什么?

I want to do something like in iPhone development: reposition controls manually without recreating the whole view.
what are pros and cons of this approach?

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

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

发布评论

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

评论(1

诗化ㄋ丶相逢 2024-12-25 11:52:11

希望这对某人有用。

如果您不想在方向更改上重新创建视图,您唯一需要的就是更改清单文件中相应的 Activity,如下所示:

android:configChanges="keyboardHidden|orientation|keyboard"

如果您想手动重新定位控件,请覆盖 onConfigurationChanged 并重新定位您需要的所有内容

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // reposition and/or hide/show controls here
} 

Hopefully this will be useful for somebody.

if you don't want ro re-create your view on orientation change, the only thing you need is to change corresponding Activity in manifest file like this:

android:configChanges="keyboardHidden|orientation|keyboard"

if you want to reposition controls manually, override onConfigurationChanged and reposition everything you need there

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

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