简体   繁体   English

如何锁定屏幕方向

[英]How to lock screen orientation

Is there a way how to lock the screen orientation but still be able to listen for device orientation changes? 有没有办法如何锁定屏幕方向,但仍然能够听取设备方向的变化? My UI consists of an ImageView and few buttons at the bottom. 我的UI由一个ImageView和底部的几个buttons组成。 The application screen orientation should be locked but the images on the buttons should change when the device orientation changes. 应锁定应用程序屏幕方向,但是当设备方向更改时,按钮上的图像应该会更改。

Thanks in advance. 提前致谢。

Yes, there is a way. 是的,有一种方法。 In the AndroidManifest.xml, where your activity is declared, you need to add another property configChanges as following. 在声明活动的AndroidManifest.xml中,您需要添加另一个属性configChanges ,如下所示。

<activity android:name="YourActivity" 
          android:configChanges="orientation|screenSize" />

This means your activity will handle orientation and currently available size changes by itself. 这意味着您的活动将自行处理方向和当前可用的大小更改。 Then you have to override onConfigurationChanged() method in your Activity and change images there. 然后,您必须覆盖Activity中的onConfigurationChanged()方法并在那里更改图像。

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

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