2013-12-20 26 views
4

我已經看過這個地方的圖片,但從某個時候回答的地方通常是「這是一個Android 2.3的已知問題」我使用4.4,所以這是肯定的不是答案。Android模擬器旋轉,但應用程序不重繪

我有關於最簡單的程序:「你好,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; 
} 

} 
+0

當方向更改活動被破壞並重新創建時。 – Raghunandan

+1

郵政編碼爲'Hello.java' –

+0

發佈您的代碼您好。java –

回答

2

顯然,一切舊的又是新的:orientation change bug in 4.4

「他們overthink管道越多,越容易堵塞排水。」

很高興知道我沒有遺漏明顯的東西; OTOH這是谷歌質量保證方面的一個非常明顯的失敗......在沒人看的時候,比爾蓋茨在那裏偷偷溜進去了嗎?或者他們是否貪婪&試圖通過挖掘模擬器來銷售手機進行測試?看起來我的將來有一個設備。

編輯:

參考:由CommonsWare,Android的框架工程師回答。

Impossible to rotate the emulator with android 4.4

2

如果你是初學者,你應該通過this reference document瞭解Activity lifecycle

在這裏,我包括幾個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(); 
} 


} 

我希望這會有所幫助!

+0

我期待在屏幕旋轉時我會看到第二條消息出現,但實際上並沒有發生。我已經提出了你的答案,因爲它是非常有用的信息,但不幸的是,我留下了旋轉的模擬器外殼內的非旋轉內容。 – ssdscott

+0

@ssdscott:是的,你說得對,仿真器4.4有一個bug –

相關問題