简体   繁体   English

将元素方向从纵向更改为横向模式

[英]Change elements orientation from portrait to landscape mode

我希望在设备处于纵向模式时有两个垂直方向的按钮,在横向时有水平方向。如何只使用.xml文件获取它?我可以使用类似“styles.xml”和如果我有肖像这样做,如果我有风景做另一个吗?谢谢

The layouts in /res/layout are applied to both portrait and landscape. / res / layout中的布局适用于纵向和横向。

To use a different layout in landscape, create a folder /res/layout-land and create another xml file here with the same name. 要在横向中使用不同的布局,请创建一个文件夹/ res / layout-land,并在此处使用相同的名称创建另一个xml文件。 Android will automatically choose the layout corresponding to the current screen orientation. Android会自动选择与当前屏幕方向对应的布局。

EDIT : 编辑:

If you cannot create a second folder or are concerned about performances, then you can override the onConfigurationChanged() method, as explained here . 如果您无法创建第二个文件夹或关注性能,则可以覆盖onConfigurationChanged()方法,如此处所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM