【问题标题】:Android screen orientation handling issueAndroid屏幕方向处理问题
【发布时间】:2012-12-24 19:58:17
【问题描述】:

我正在开发 android 动态壁纸应用程序,需要正确处理屏幕方向更改。

目前我为此使用onConfigurationChanged(在这种方法中,我需要更改我的LWP屏幕元素的坐标。我使用andengine)。在模拟器和我的测试手机上一切正常,但我的一些客户使用 Samsung Galaxy Note2 (t03g)LG 惊险(LGE LG-P925) 报告了不正确的问题屏幕方向更改期间的应用程序工作。

我手头没有这些电话,但可以假设问题与未呼叫onConfigurationChanged 有关。

使用onConfigurationChanged方法是否正确?也许我需要使用onSurfaceChanges 或类似的东西?你能建议我解决这个问题的正确方法吗?

Alos,我已将 android:configChanges="keyboardHidden|orientation" 添加到我的 AndroidManifest.xml 中:

<activity
            android:name=".WallpaperSettings"
            android:configChanges="keyboardHidden|orientation"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.PREFERENCE" />
            </intent-filter>
        </activity>

【问题讨论】:

标签: java android andengine screen-orientation live-wallpaper


【解决方案1】:

在我处理方向变化的动态壁纸中,我使用onConfigurationChange() 方法来检查方向变化,但我对这两款手机没有任何直接经验,尽管我从未收到任何关于它们的投诉.我的方法看起来是这样的:

   @Override
   public void onConfigurationChanged(Configuration newConfig) {
       super.onConfigurationChanged(newConfig);

       // Checks the orientation of the screen  
       if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
         rotated = true;
       }
       else {
         rotated = false;
       }
   }

draw() 方法中,我检查rotated 布尔值。 onSurfaceChanged() 中有额外的检查以在方向改变时更正分辨率的变化。

我的清单文件中根本没有 android:configChanges="keyboardHidden|orientation"

【讨论】:

    【解决方案2】:
     android:configChanges="orientation|screenSize"
    

    注意:从 Android 3.2(API 级别 13)开始,“屏幕尺寸” 当设备在纵向和横向之间切换时也会发生变化 方向。因此,如果您想防止运行时重新启动由于 为 API 级别 13 或更高级别开发时的方向更改(如 由 minSdkVersion 和 targetSdkVersion 属性声明),你 除了“方向”之外,还必须包含“screenSize”值 价值。也就是说,你必须 decalare android:configChanges="orientation|screenSize"。但是,如果您的 应用程序以 API 级别 12 或更低级别为目标,那么您的活动始终 自行处理此配置更改(此配置更改 不会重新启动您的活动,即使在 Android 3.2 或 更高的设备)。

    【讨论】:

      猜你喜欢
      • 2011-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多