Android Orientation标记错误

时间:2014-05-29 05:25:35

标签: android

我正在使用eclipse android 我想了解方向更改,当方向更改gget logid消息时,下面是我们的代码

package com.example.orientation;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.Configuration;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
 }


 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
     // Inflate the menu; this adds items to the action bar if it is present.
     getMenuInflater().inflate(R.menu.main, menu);
     return true;
 }
 @Override
 public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    super.onConfigurationChanged(newConfig);

    Log.d("Android","orientation changes"+newConfig.orientation);
 }
}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.orientation"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.orientation.MainActivity"
        android:label="@string/app_name" 
      android:configChanges="orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

这里我们没有在log cat中收到消息。我正在尝试记录方向的整数值。代码中没有错误

1 个答案:

答案 0 :(得分:0)

使用  <activity android:name="com.example.orientation.MainActivity" android:label="@string/app_name" android:configChanges="orientation|screenSize">

而不是...... <activity android:name="com.example.orientation.MainActivity" android:label="@string/app_name" > android:configChanges="orientation|screenSize">

看到差异