onConfigurationChanged,它仍然呈现的第一个布局 [英] onConfigurationChanged-it's still showing the first layout
问题描述
我有一个处理的配置更改的活动。但现在我必须改变 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屋!