当我将Android手机颠倒时,我的Activity不会旋转以颠倒显示布局,而是保持横向模式。我尝试了一个非常简单的HelloWorld应用程序。我在清单中添加了android:configChanges="orientation"
并在活动中覆盖了onConfigurationChange()
以在那里设置断点。颠倒旋转设备会产生一次配置更改,从纵向(颠倒)转到横向,但不会从横向转换为纵向(颠倒)。这是Android的问题还是有我需要做的事情?颠倒旋转不会触发配置更改
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hello.world"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:configChanges="orientation"
android:name=".HelloWorldActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
活动:
public class HelloWorldActivity
extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
Log.e("MDO", "orientation change: landscape");
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
Log.e("MDO", "orientation change: portrait");
}
}
}
你确定你的设备做到了吗?我很少看到允许这样的应用。 – DeeV 2012-07-20 19:09:17
我还没有看到这种行为,我尝试了一些标准的应用程序(设置,浏览器等),但它可能与'android:screenOrientation =“fullSensor”' – 2012-07-20 20:44:38