onConfigurationChanged,它仍然呈现的第一个布局第一个、布局、onConfigurationChanged

2023-09-07 16:56:46 作者:你不配拥有我

我有一个处理的配置更改的活动。但现在我必须改变 layout.I试图在onConfigurationChanged回调只是重新设置布局,希望会得到正确的布局(土地),但它仍然显示 为纵向视图的第一个布局(会有两个布局(同名)被放置在RES / 布局和RES /布局土地:)

I have an activity which handles configuration changes. But now i have to change layout.I tried in onConfigurationChanged callback just to set again the layout and hoping will get the correct layout(land) but it's still showing the first layout for portrait view ( there two layout(same name) are placed in res/ layout and res/layout-land :)

如果我删除Android:configChanges =方向,它的工作原理是应该的,但我需要处理onConfigurationChanged。我该怎么办??

if I delete android:configChanges="orientation", it works should be, but ı need to handle onConfigurationChanged. What should I do??

推荐答案

如果您在 / RES /布局的纵向布局的main.xml 和你的景观布置的main.xml / RES /布局土地,和你 onConfigurationChanged()是这样的:

If you have your portrait layout main.xml in /res/layout and your landscape layout main.xml in /res/layout-land, and your onConfigurationChanged() looks like this:

    public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);                
            setContentView(R.layout.main);
    ...
    ...
    ...

    }

而在你的清单,你应该有安卓configChanges =keyboardHidden |定位

然后,它应该工作正常,因为这确实在我的应用程序。这是你在​​做什么?

Then it should work fine, as this does in my app. Is this what you are doing?