Android 任意方向 XML 布局
您好,我正在尝试使我的布局与所有方向屏幕类型(横向/纵向)兼容。为此,我使用 layout-land
和 layout-port
。
这适用于只有 2 个方向位置(横向和纵向)的设备,但如果我旋转支持 4 个方向位置(向左/向右、端口颠倒/颠倒)的设备,则不起作用。仅在默认陆地位置上工作,但如果我在其他横向位置上旋转设备,Android 会选择 layout-port
布局而不是 layout-land
。
如何在 XML 中解决这个问题?或者唯一的解决方案是管理自己的方向变化?
Hello I am trying to make my layout compatible with all orientation screen types (landscape/portrait). For that I am using layout-land
and layout-port
.
This works for devices that have only 2 orientation positions (landscape and portrait) but is not working if I rotate a device that supports 4 orientation positions (land left/right, port upside down/upside). Is working only on default land position but if I rotate the device on the other landscape position, android choose the layout-port
layouts instead of layout-land
.
How can I solve this problem in XML? Or the only solution is to manage myself the orientation changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这里您会注意到,我只是监听 StageOrientationEvent.ORIENTATION_CHANGE 事件。当事件触发时,舞台有五种可能的方向:默认、向左旋转、向右旋转、颠倒和未知。
http://www.unitedmindset.com/ jonbcampos/2010/09/27/air-for-android-screen-orientation/
Here you will notice that I just listen to the stage for the StageOrientationEvent.ORIENTATION_CHANGE event. When the event fires there are five possible orientations that the stage can be in: default, rotated left, rotated right, upside down, and unknown.
http://www.unitedmindset.com/jonbcampos/2010/09/27/air-for-android-screen-orientation/
您无法使用 XML 来完成此操作。你必须以程序化的方式进行。要检测方向变化,您可以使用OrientationEventListener
You can't do this using XML. You have to do programmatic. To detect orientation change you can use OrientationEventListener
你的targetSDK必须是2.2(当reverseLandscape和reversePortrait方向被引入时......很确定它是在2.2中)并且你的设备必须支持这些方向。例如,索尼平板电脑 S 不会进入反向横向模式,但会进入反向纵向模式
Your targetSDK has to be 2.2 (when the reverseLandscape and reversePortrait orientations were introduced... pretty sure it was in 2.2) and your device has to support these orientations. For example a Sony Tablet S won't go into reverseLandscape but will do reversePortrait
看来布局土地有效..问题是我自己管理方向变化并且只采用了两种类型的方向..
(我管理方向只是为了获取应用程序标题并使其在横向全屏显示。 .)
不过还是谢谢你的回答
It seems that the layout-land works.. the problem was that I managed the orientation change by myself and took only 2 types of orientation..
(I manage the orientation just to get down the app title and make it full screen in landscape..)
Thank you for your answers though