为什么我的应用程序停止支持屏幕方向更改?
我创建了一个新的 Android 应用程序,其中包含基本的 Toast 消息和选项菜单。有一段时间,该应用程序支持方向更改没有问题,但现在它似乎不再关心自动旋转。是否有一些我在不知情的情况下擦除或设置的魔法设置?自从我第一次创建它以来,实际上没有任何代码更改,并且它运行没有问题。
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>
I created a new Android application with a basic Toast message and options menu. For a while the app supported orientation changes without issue, but now it seems to no longer care about auto-rotating. Is there some magic setting that I wiped or set without knowing it? The literally has had no code changes since I first created it and it worked without issue.
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查您的手机是否启用了旋转功能,有时我也忘记了:P
Please check if you have rotation enable on phone, sometimes I forgot it too :P