2011-08-03 99 views
0

當我嘗試切換到屏幕的橫向時,出現錯誤。橫向打印工作的XML佈局就好了,因爲我通過強制應用到以水平方向出現在AndoridManifest.xml測試它:在縱向/橫向之間切換時遇到問題

android:screenOrientation="portrait" 

這裏是logcat的日誌追蹤

08-03 09:09:33.660: INFO/WindowManager(71): Setting rotation to 1, animFlags=1 
08-03 09:09:33.690: INFO/WindowManager(71): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/1 nav=3 orien=2 layout=17} 
08-03 09:09:33.849: INFO/WindowManager(71): onOrientationChanged, rotation changed to 1 
08-03 09:09:34.010: DEBUG/StatusBar(71): updateResources 
08-03 09:09:34.251: DEBUG/AndroidRuntime(479): Shutting down VM 
08-03 09:09:34.251: WARN/dalvikvm(479): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 
08-03 09:09:34.251: ERROR/AndroidRuntime(479): Uncaught handler: thread main exiting due to uncaught exception 
08-03 09:09:34.280: ERROR/AndroidRuntime(479): android.util.AndroidRuntimeException: requestFeature() must be called before adding content 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:285) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at android.app.Activity.requestWindowFeature(Activity.java:2561) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at com.news.reader.Home.onConfigurationChanged(Home.java:85) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:3607) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:3673) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1864) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at android.os.Looper.loop(Looper.java:123) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at android.app.ActivityThread.main(ActivityThread.java:4203) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at java.lang.reflect.Method.invoke(Method.java:521) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 
08-03 09:09:34.280: ERROR/AndroidRuntime(479):  at dalvik.system.NativeStart.main(Native Method) 
08-03 09:09:34.299: INFO/Process(71): Sending signal. PID: 479 SIG: 3 
08-03 09:09:34.299: INFO/dalvikvm(479): threadid=7: reacting to signal 3 
08-03 09:09:34.410: INFO/dalvikvm(479): Wrote stack trace to '/data/anr/traces.txt' 

有一個錯誤,這是告訴我,我應該在設置佈局內容之前做一些事情。有人可以解釋我缺少的東西或給出重定向,在這裏解釋。

UPDATE

我叫requestWindowFeature(Configuration.ORIENTATION_LANDSCAPE);後,我還是得到了同樣的錯誤:

@Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     setContentView(R.layout.home_landscape); 

     createUI(); 
    } 

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.home_portrait); 

     createUI(); 
    } 
+0

只需評論你的onConfigurationChanged()方法,並檢查你是否得到相同的異常。 –

+0

好的,我找出是什麼原因導致錯誤,但不知道爲什麼?我編輯了我的**更新**。如果你能解釋導致錯誤的原因,在編輯之前。 – nenito

+1

使用requestWindowFeature(),並再次在onConfigurationChanged做同樣的事情()...你只是upvoted不接受......你也許已刪除標題欄 –

回答

1

你得到例外上面,因爲,如果您有任何活動的setContentView()之前調用requestWindowFeature()

+0

我更新了我的代碼,但仍然得到了同樣的錯誤。你可以看到我在** UPDATE **中做了什麼。 – nenito

相關問題