我创建了一个带有基本Toast消息和选项菜单的新Android应用程序。有一段时间,应用程序支持的方向更改没有问题,但现在它似乎不再关心自动旋转。是否有一些魔法设置,我在不知情的情况下擦拭或设置?自从我第一次创建代码以来,字面上没有代码更改,并且它没有问题。
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.somedomain.appname"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".StartActivity" 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>
StartActivity.java
package com.somedomain.appname;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
/** Main Activity **/
public class AppName extends Activity {
/** Called when someone specifies to view the options menu **/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Set
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.navigate, menu);
// Return
return true;
}
/* Handle options menu selections */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.itemNewGame:
// New Game
return true;
case R.id.itemSettings:
// Settings
return true;
case R.id.itemAbout:
// About
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
// Super
super.onCreate(savedInstanceState);
// Set
setContentView(R.layout.main);
// First time?
if ( savedInstanceState == null ) // null the first time
{
// Splash
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.splash, (ViewGroup) findViewById(R.id.frameLayout1));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/frameLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:src="@drawable/logo" src="@drawable/logo" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="centerInside" android:padding="30dip"/>
</FrameLayout>
答案 0 :(得分:6)
请检查您是否在手机上启用了旋转功能,有时我也忘记了:P