【发布时间】:2013-12-20 05:56:16
【问题描述】:
我在其他地方看到过这样的图片,但从前一段时间,答案通常是“这是 Android 2.3 的一个已知问题”,我使用的是 4.4,所以这绝对不是答案。
我有一个最简单的程序:“你好,Android”。当我启动模拟器时,它以纵向模式加载。使用 Fn-Ctrl-F11 (Mac),模拟器旋转到横向模式。但应用程序和手机控件不会重绘 - 整个画面只是横向显示。
这是清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.helloandroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
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.test.helloandroid.Hello"
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>
以及活动 XML 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Hello" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
我正在使用 Eclipse 构建,ADT 捆绑包构建 v22.3.0-887826,虽然我无法想象这对于这么微不足道的事情很重要。
我的模拟器适用于设备 Galaxy Nexus,Android 4.4 API 级别 19。我已经尝试过使用标记和未标记的硬件键盘。我发现了对“键盘盖支持”设置的引用,这是我在任何地方都没有看到的 - 此评论来自 3/12,因此可能已过时。
这是我的第一个 Android 应用程序,所以我完全是在这个环境中调试的新手。 TIA 对我遗漏的任何建议。
编辑:为 hello.java 添加代码
package com.test.helloandroid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Hello extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello, menu);
return true;
}
}
【问题讨论】:
-
当方向改变时活动被销毁并重新创建。
-
Hello.java的邮政编码 -
发布你的Hello.java代码
-
@MehulJoisar 感谢您的链接 - 以及 Log 和 Toast 建议。我已经更新了我的代码,使其具有与您的建议相同的日志消息。有趣的是,当我第一次通过 Eclipse 启动应用程序时,我得到了 OnCreate - 但是当我旋转模拟器时,我没有收到 Toast 消息。
标签: android eclipse android-emulator autorotate