如何在android中调整xml文件的纵向和横向模式的正确界面
我的问题是,我在 Android 中以纵向模式准备 xml,但是当我尝试使用手机运行应用程序并获取横向模式时,我的界面崩溃了。图片变小并且屏幕上不显示按钮。我希望无论手机处于横向模式还是纵向模式,我的界面都是相同的。 我该如何解决这个问题?我可以为一个类准备两个不同的xml,一个用于横向模式,另一个用于纵向模式,或者还有其他解决方案吗? 谢谢
My problem is that I prepare my xml in portrait mode in Android but when I try to run the application with phone and get the landscape mode, my interface crash. Picture gets smaller and buttons don't appear on the screen. I want my interface to be the same whether the phone is in landscape mode or portrait mode.
How can I solve this problem? Can I prepare two different xml for one class, one for landscape and the other for portrait mode or is there any other solution?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里你有两个选择。第一个是将 android:configChanges 属性添加到清单中的该 Activity:
这将阻止 android 在方向更改时重新创建该 Activity。相反,将调用活动的 onConfigurationChanged 方法。
另一种是制作另一种布局,在设备横向时使用。它需要与纵向布局命名相同,并放在布局土地下。
可能还有其他选择,这些只是我所知道的。
You have two options here. The first is to add the android:configChanges attribute to that activity in the manifest:
This will stop android from recreating the activity when the orientation changes. Instead the activity's onConfigurationChanged method will be called.
The other is to make another layout that will be used when the device is in landscape. It would need to be named the same as the portrait layout and put under layout-land.
There's probably other options as well, these are just the ones that I know of.
您可以轻松地在不同方向上使用不同的布局,请参阅 Providing 中的“屏幕方向” Resources
您所需要做的就是在 res 下创建一个布局端口或布局土地目录,并将备用 XML 放入其中。
You can easily have different layouts in different orientations, see "Screen Orientation" in Providing Resources
All you need to do is create a layout-port or layout-land directory under res, and put the alternate XML in there.