android 旋转器的屏幕方向处理
我有一个活动,其中有一个旋转器。因为对于纵向和横向模式,我有不同的布局,所以我在 onConfigurationChanged 方法中更改布局
@Override
public void onConfigurationChanged(Configuration conf) {
super.onConfigurationChanged(conf);
setContentView(R.layout.layout);
initUI();
}
,但问题是当我更改方向时,我的微调器会重新创建,因此如果微调器在纵向模式下打开,它会接近横向模式。我的要求是:如果在任何模式下打开,都应该在方向改变后打开。请让我知道如何处理这种情况。
I have a activity in which there is a spinner. since for portrait and landscape mode i have different layout so I am changing layout in onConfigurationChanged
method
@Override
public void onConfigurationChanged(Configuration conf) {
super.onConfigurationChanged(conf);
setContentView(R.layout.layout);
initUI();
}
but the problem is when I change orientation , my spinner is recreated so if spinner is open in portrait mode it get close in landscape mode.My requirement is : if it is open in any mode , it should be open after orientation change.can you please let me know how to handle this situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试 spinner 的 PerformClick() 方法
try spinner's performClick() method
要停止重新创建 Spinner,您可以将其添加到清单文件中,
但是通过添加此内容,当您旋转设备时,您的布局将不会自动更改,因此您必须像这样手动管理它,
有关更多信息,您可以查看我的回答
这里
。To stop re-creation of your Spinner you can add this in your Manifest file
But by adding this your Layout will not be changed automatically when you rotate your device, so you have to manage that manually like this,
For more information you can check my answer
here
.一旦方向改变,销毁方法就会被调用,你的活动会再次重新创建。为了避免调用 destroy 方法,您需要在清单文件中添加以下代码。但在这种情况下只能使用一种布局,如果您想重新发布内容,则需要动态执行此操作。
Once the orientation changes, destroy method get called and your activity re-create once again. To avoid destroy method get called you need to add below codes in manifest file. But in this case only one layout can be used, if you want to repostion your contents you need to do it dynamically then.