Android的屏幕方向变化对平板电脑不同的行为平板、屏幕、方向、不同

2023-09-07 02:16:54 作者:薄荷糖べ微微凉

我有一个活动:

android:screenOrientation="portrait"

和code:

if(blah blah blah)
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)

在活动的onCreate。 1.当测试的智能手机setRequestedOrientation原因破坏活动,并与所需的屏幕方向重新创建。 2.当测试平板设备在这code只运行一次的活动。经过setRequestedOrientation它只是将继续进行破坏并重新创建活动。发生这种情况时,启动code没有debuger或无断点的onCreate。如果我停止的onCreate功能 - 我在日志中看到 - 再破坏和的onCreate。 如何捕捉具体情况与平板电脑?

in activity onCreate. 1. When test on smartphone "setRequestedOrientation" causes destroy activity and create again with desired screen orientation. 2. When test on tablet device this code runs only once activity. After "setRequestedOrientation" it just continues without destroy and create again activity. This happens when start code without debuger or without breakpoint in onCreate. If I stop in onCreate function - I see in logs - destroying and onCreate again. How to catch specific situation with tablet?

更新: - '方向锁定,如果关闭时与平板电脑出现问题。以同样的方式如果方向锁定启用程序运行在智能手机上。

UPDATE: - Problem with tablet occurs when 'Orientation lock' if off. If 'Orientation lock' is enabled program works in same way as in smartphone.

UPDATE2: - 是否有可能设置preffered屏幕方向整个应用程序。因此,活动开始时,知道所需的方向。这将使unnessesary电话'setScreenOrientation,避免次活动创作。

UPDATE2: - Is it possible to set preffered screen orientation to whole application. So when activity starts to know desired orientation. This will make unnessesary call 'setScreenOrientation' and avoid second activity creation.

推荐答案

没有..您不能设置preffered屏幕方向的整个应用程序 ...相反,你应该呼吁setScreenOrientation在各自的activies只有... Refere这里这个链接...

No.. you cannot set preffered screen orientation for whole application... instead you should call for setScreenOrientation in respective activies only... Refere this link here...