默认屏幕方向Android设备 [英] Default screen orientation on android devices

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

问题描述

我已经看到了很多问题,在这里对屏幕方向,但我的是一种不同。
我试图找到搞清楚在运行时什么是触摸屏的默认方向的一种方式。
即:对于平板电脑它的景观,手机是肖像等
我需要这个信息,因为我是直接涉及触摸屏的硬件,并且它的x,y格是恒定的,而不是根据当前系统的方向。照片
任何想法

编辑:我会改进我的问题:
我怎样才能知道,如果物理tounch屏幕,是面向喜欢系的方向纵向或横向。

i've seen alot of questions here about screen orientation but mine is kind of different.
I'm trying to find a way of figuring out at run-time what is the default orientation of the touch-screen.
i.e: for tablets it's landscape, for phones it's portrait etc.
I need this info because i'm dealing directly with the touchscreen hardware, and it's x,y grid is constant, and not based on the current system orientation.

any ideas?

I'll refine my question:
How can i tell if the physical tounch screen, is oriented like system orientation portrait or landscape.

编辑(答):好的,那么: getSystemService(Context.WINDOW_SERVICE))getDefaultDisplay()getRotation()
会给你从默认的触摸屏轴的当前旋转度。
例如:
平板电脑,其中触摸屏轴是与横向排列,在obove将景观返回0
在手机上,其中触摸屏轴是与纵向排列的obove将返回0的肖像。好极了! :)

Edit (Answer): OK, so: getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation()
will give you the current rotation degree from the default touch screen axis.
e.g:
On tablets, where the the touch screen axis are aligned with the landscape orientation, the obove will return 0 on landscape.
On phones where the touch screen axis are aligned with the portrait orientation, the obove will return 0 on portrait. yay! :)

推荐答案

没有缺省值。不要写你的code假设肖像是默认的。如果你的应用程序是方向敏感的,把你的布局文件布局端口和布局的土地,而不是在布局。布局是只对那些活动和对话框哪些不是取向特异性

There is no default. Don't write your code assuming that portrait is the default. If your app is orientation-sensitive, put your layout files in layout-port and layout-land, not in layout. layout is only for those activities and dialogs which are not orientation-specific.

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

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