Android 可能会为单向活动使用错误的布局文件
我偶然发现,如果您有一个设置为一个方向的 Activity,但包含不同方向的单独布局文件,则当该 Activity 首次启动时,它将使用与设备物理匹配的布局文件进行膨胀。方向,并且不是与活动方向匹配的布局文件。因此,如果 AndroidManifest.xml 指定
<activity
android:name=".activities.LandscapeGardener"
android:screenOrientation="sensorLandscape">
<!-- note for new readers: sensorLandscape is like landscape, but also
works upside-down.
Other activity stuff would go here. -->
</activity>
并且在 layout-port
文件夹中有 LandscapeGardener
的布局,如果 Activity 以纵向加载,则特定于纵向的布局将会膨胀。
顺便说一句,我们遇到这种情况的原因是我们正在开发的 Activity 存在一些特定于纵向的错误,因此我们决定在修复这些错误时抑制用户的纵向模式 - 但当然这个问题使得抑制有些局部!
请注意,如果设备在启动时方向正确,则不会更改为不正确的布局。
I discovered by accident that if you have an Activity that is set to one orientation, but contains a separate layout file for a different orientation, when the Activity is first started it will be inflated with the layout file that matches the device's physical orientation and not the layout file that matches the Activity's orientation. Thus if AndroidManifest.xml specifies
<activity
android:name=".activities.LandscapeGardener"
android:screenOrientation="sensorLandscape">
<!-- note for new readers: sensorLandscape is like landscape, but also
works upside-down.
Other activity stuff would go here. -->
</activity>
and there is a layout for LandscapeGardener
in the layout-port
folder, if the Activity is loaded in portrait, the portrait-specific layout will be inflated.
The reason we have this situation, by the way, is that an Activity we're developing has some portrait-specific bugs, so we decided to suppress portrait mode for users while we fix them—but of course this problem makes the suppression somewhat partial!
Note that if the device is correctly oriented at startup, it will not change to the incorrect layout.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试仅横向而不是传感器横向。我很确定它有效。
instead of sensorLandscape, try just landscape. i'm pretty sure it works.