简体   繁体   English

Android屏幕方向处理问题

[英]Android screen orientation handling issue

I'm working on the android live wallpaper applications and need to correctly handle screen orientation changes. 我正在使用android动态壁纸应用程序,并且需要正确处理屏幕方向更改。

Currently I use onConfigurationChanged for this purpose(in this method I need to change coordinates of my LWP screen elements. I use andengine ). 当前,我为此使用onConfigurationChanged (在这种方法中,我需要更改我的LWP屏幕元素的坐标。我使用andengine )。 Everything works fine on the emulators and my test phones, but some my customers with Samsung Galaxy Note2 (t03g) , LG thrill(LGE LG-P925) reports the issues with incorrect application work during the screen orientations change. 在仿真器和我的测试手机上,一切正常,但一些使用Samsung Galaxy Note2(t03g)LG thrill(LGE LG-P925)的客户报告了屏幕方向更改期间应用程序工作不正确的问题。

I don't have these phones on hand, but can suppose that the issue is related to onConfigurationChanged not being called. 我手头没有这些电话,但可以假设问题与onConfigurationChanged没有被调用有关。

Is it correct to use onConfigurationChanged method ? 使用onConfigurationChanged方法是否正确? Maybe I need to use onSurfaceChanges or something like that ? 也许我需要使用onSurfaceChanges或类似的东西? Could you please suggest me the correct way to solve this issue ? 您能否建议我解决此问题的正确方法?

Alos, I have added android:configChanges="keyboardHidden|orientation" into my AndroidManifest.xml : Alos,我已经在我的AndroidManifest.xml添加了android:configChanges="keyboardHidden|orientation"

<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>

In my live wallpaper, which handles orientation changes, I use the onConfigurationChange() method to check for orientation changes, but I don't have any direct experience with the 2 phones, though I've never gotten any complaints about them. 在处理方向变化的动态壁纸中,我使用onConfigurationChange()方法检查方向变化,但是我onConfigurationChange()手机没有任何直接的经验,尽管我从未对它们有任何抱怨。 My method looks something along the lines of: 我的方法看起来类似于:

   @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;
       }
   }

And in the draw() method, I check the rotated boolean. 然后在draw()方法中,检查rotated布尔值。 There's additional checks in the onSurfaceChanged() to correct for resolution changes when the orientation changes. onSurfaceChanged()还有其他检查,以在方向更改时纠正分辨率更改。

I don't have android:configChanges="keyboardHidden|orientation" in my manifest file at all. 我的清单文件中根本没有android:configChanges="keyboardHidden|orientation"

 android:configChanges="orientation|screenSize"

Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. 注意:从Android 3.2(API级别13)开始,当设备在纵向和横向之间切换时,“屏幕尺寸”也会更改。 Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. 因此,如果要防止在开发API级别13或更高级别时(如minSdkVersion和targetSdkVersion属性所声明的),由于方向更改而导致运行时重新启动,则除了“ orientation”值外,还必须包括“ screenSize”值。 That is, you must decalare android:configChanges="orientation|screenSize". 也就是说,您必须贴花android:configChanges =“ orientation | screenSize”。 However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device). 但是,如果您的应用程序以API级别12或更低级别为目标,则您的活动始终会自行处理此配置更改(即使在Android 3.2或更高版本的设备上运行,此配置更改也不会重新启动您的活动)。

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

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