平板上只能竖着启动app,横着打不开

今天发现 在我的平板(MotorolaXoom)上只能竖着启动app,横着打不开,好奇怪的现象。一开始还以前,只有模拟器里会是这样的,现在真机买回来后,才发现真机上也有这个问题。

难道是因为我的每个Activity都设置了 <activity android:name=".activity.XXXActivity"android:screenOrientation="portrait"> 可是项目要求就是portrait模式啊。

Landscape layout: The "normal" orientation for tablet-type devices is usually landscape(wide), so you should be sure that your activities offer a layout that's optimized for a wideviewing area.

You can specify landscape resources with the land resourcequalifier, but if you want alternative resources for an extra large landscape screen, youshould use both thexlargeland qualifiers. For example,res/layout-xlarge-land/. The order of the qualifier names is important; seeProviding Alternative Resources for more information. and


经测试在3.2的simulator上是可以在屏幕横着的时候启动app的,跟手机上的效果一样。我又试着用3.2来编译,然后再运行在真机上,还是有这个问题。


感觉问题出在,当程序运行时,app根据 android:screenOrientation="portrait"的方式来显示,但是这时候,机器是横着的,并不是竖着的。重力感应到了屏幕的方向不了,所以机器作了强制调整!这应该是一个机器设计问题。现在考虑能不能让程序在运行时,强制取消机器的屏幕方向随重力感应。

于是,解决方案就来了,在每一个Activity的配置当中,添加 android:configChanges="orientation|keyboardHidden"

也不用重写:

@Override
public void onConfigurationChanged(Configuration newConfig) {
// ignore orientation/keyboard change
super.onConfigurationChanged(newConfig);
}


这个方法是用来自己指定当屏幕方向发生时,app应该做什么。这里我的app并不支持landscape,因此什么也不必做。因此就能固定竖屏显示了,不随重力感应变化。


参考资料:

http://stackoverflow.com/questions/2150287/force-an-android-activity-to-always-use-landscape-mode




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值