Android模拟器旋转但应用程序不重绘。

4
我曾经在其他地方看到过这种情况的图片,但是那是一段时间以前了,一般的答案是“这是Android 2.3中已知的问题”。我正在使用4.4,所以肯定不是这个答案。
我有一个非常简单的程序:“Hello, 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>

以及Activity的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 bundle build v22.3.0-887826,虽然我认为这对于这种小事并不重要。我的模拟器是针对Galaxy Nexus设备的,Android 4.4 API级别为19。我已经尝试过将硬件键盘设置为存在和不存在。我发现了一个“键盖支持”设置的参考,但我还没有在任何地方看到过 - 这个评论是来自3/12,所以可能已经过时了。这是我的第一个Android应用程序,因此我完全是在这个环境中进行调试的新手。谢谢您提供任何有关我错过了什么的建议。
编辑:添加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;
}

}

当屏幕方向改变时,Activity 会被销毁并重新创建。 - Raghunandan
1
Hello.java的邮政编码是多少? - Mehul Joisar
请发布你的Hello.java代码。 - Dehan Wjiesekara
@MehulJoisar 感谢您提供的链接,以及日志和提示建议。 我已更新我的代码,使其具有与您建议相同的日志消息。 有趣的是,当我通过Eclipse首次启动应用程序时,我会得到OnCreate,但是当我旋转模拟器时,我不会收到任何Toast消息。 - ssdscott
2个回答

2
如果您是初学者,应该阅读此参考文档,了解Activity生命周期
在这里,我会包含一些LogToast,以便更容易地理解当您旋转屏幕时发生的过程。 示例:
package com.test.helloandroid;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class Hello extends Activity {


private static final String TAG = "Hello";

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

    Log.d(TAG, "onCreate");
    Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
}


@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;
}

@Override
protected void onResume() {
    super.onResume();

    Log.d(TAG, "onResume");
    Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
}

@Override
protected void onPause() {
    super.onPause();

    Log.d(TAG, "onPause");
    Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
}


}

I hope it will be helpful !!


我本以为当屏幕旋转时会出现第二条消息,但实际上并没有发生。我已经点赞了你的答案,因为它提供了非常有用的信息,但不幸的是,在旋转的模拟器外壳中,我仍然无法旋转内容。 - ssdscott

2

显然,一切旧的东西都变新了:4.4版本中的方向更改错误

"他们过度思考管道,根本没有注意堵塞的问题。"

很高兴知道我没有错过什么明显的东西;另一方面,这是谷歌质量保证方面相当明显的失败...比尔·盖茨是趁没人注意偷偷溜进去了吗?或者他们太贪婪,试图通过搞砸模拟器来销售测试手机?看起来未来我的设备会有问题。

编辑:

参考:由Android框架工程师CommonsWare回答。

无法使用Android 4.4旋转模拟器


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接