onConfigurationChanged,它仍然呈现的第一个布局 [英] onConfigurationChanged-it's still showing the first layout

查看:213
本文介绍了onConfigurationChanged,它仍然呈现的第一个布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理的配置更改的活动。但现在我必须改变 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?

这篇关于onConfigurationChanged,它仍然呈现的第一个布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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