Android的 - 处理屏幕方向 [英] Android - Handle Screen Orientation

查看:181
本文介绍了Android的 - 处理屏幕方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作,根据屏幕方向具有不同的行为Android应用程序。

I'm currently working on an Android application that have different behaviors according to the screen orientation.

我使用getWindowManager()。getDefaultDisplay()。getRotation()来获得在onCreate()方法的屏幕方向,并从那里管理。

I'm using getWindowManager().getDefaultDisplay().getRotation() to get the screen orientation in the onCreate() method and manage from there.

基本上,我的问题是,我需要在方向控制。在横向模式下,当用户决定它,应用程序必须再次切换到肖像模式,并保持这样的,但只有等到使用变为纵向模式,再到风景​​线。

Basically, my problem is that I need a control over the orientation. In landscape mode, when the user decides it, the application must switch to portrait mode, and stays like that, but only until the use goes to portrait mode, and then again to landscape.

我使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)的景观时改变方向。问题是,用这个,我不能回去的风景线。
如果使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)中的onCreate(),问题是在几秒钟后是切换回横向模式(因为屏幕仍然在横向)。

I'm using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) to change the orientation when in Landscape. The problem is, using this, I can not go back to landscape. If I use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) in onCreate(), the problem is that is switches back to landscape mode after a few seconds (since the screen is still in landscape).

是否有任何其他的方式来管理呢?基本上,有没有办法赶上与听者中屏幕的方向变化(或其他地方比的onCreate,因为当意见被锁定在纵向模式下,它不叫)?我无法找到有关什么...

Is there any other way to manage this? Basically, is there a way to catch the screen orientation change with a listner (or anywhere else than in onCreate, since it's not called when the views is locked in portrait mode)? I can't find anything about that...

任何想法是值得欢迎的!

Any idea is welcome!

谢谢!

推荐答案

为什么不尝试创建两个布局,一个在布局的土地,一个在布局端口。当设备方向的变化,这些将被自动应用。

Why not try creating two layouts, one in layout-land and one in layout-port. These will automatically be applied when the device orientation changes.

在每个这些,创建两个不同的子布局,一个用于纵向视图,以及一个用于横向视图,并更改这些知名度,反映用户的preference。

Inside each of these, create two distinct child layouts one for a portrait view, and one for a landscape view and change the visibility of these to reflect the user's preference.

所以,你并不需要在所有办理旋转变化,让Android的管理,对于你,而你只是管理的用户覆盖。

So, you don't need to handle the rotation change at all, let Android manage that for you, and you just manage the user override.

这篇关于Android的 - 处理屏幕方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆