屏幕方向
你好 我是android新手。我遇到了一个问题,即在横向模式下,我需要一个布局视图,它没有纵向模式中存在的一些字段。我已经以这种方式创建了横向视图的布局。在我给出的活动中像纵向显示某些字段这样的条件会隐藏一些。它实际上工作正常...首先,当我从纵向转到横向时,它给出了我想要的...但是当我进入纵向模式时,它停止了应用程序。请帮助我。提前致谢
Hi
M new to android.I faced a problem i.e in landscape mode i need a layout view which doesnot have some feilds which are present in the portrait mode.I have created a layout for landscape view in such a way.In the activity i have given the conditions like if portrait display some feilds some hide.its working properly actually...first when i go from portrait to landscape it is giving what i want...but when i go to portrait mode its stopping the application.please help me.Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以制作两种不同的布局,分别放在layout-port和layout-land中。
并确保您在该活动的清单中提到了 android:configuration = "orientation"。如果我正确理解了你的话,请尝试一下。
You can make two different layouts and put them in layout-port and layout-land respectively.
And make sure that you have mentioned android:configuration = "orientation" in your manifest for that activity. Try it if i have understood you correctly.
我认为坎特什的建议可能是倒退的。如文档中所述,如果您包含 android:configChanges=如果清单中包含“orientation”,则不会自动加载正确的资源(来自布局端口或布局土地)。相反,不要在清单中提及方向。然后,您无需担心
onConfigurationChanged()
(不要覆盖它)。系统将自动关闭该活动,然后重新启动它,绑定相应版本的配置相关资源。自己处理配置更改(同样,根据文档)只是处理无法通过其他方式处理的性能问题的最后手段。I think that the advice by Kantesh may be backwards. As explained in the docs, if you include android:configChanges="orientation" in the manifest, then the correct resource (from layout-port or layout-land) won't be automatically loaded. Instead, leave out mention of orientation from the manifest. Then, you do not need to worry about
onConfigurationChanged()
(don't override it). The system will automatically shut down the activity and then restart it, binding the appropriate version of configuration-dependent resources. Handling configuration changes yourself is (again, according to the docs) only a last resort to deal with performance issues that cannot be handled in other ways.