我想改變佈局背景。動態更改佈局背景
下面是從logcat的日誌:
04-10 14:59:55.291: WARN/dalvikvm(263): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
04-10 14:59:55.309: ERROR/AndroidRuntime(263): Uncaught handler: thread Thread-8 exiting due to uncaught exception
04-10 14:59:55.331: ERROR/AndroidRuntime(263): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.ViewRoot.checkThread(ViewRoot.java:2683)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.ViewRoot.requestLayout(ViewRoot.java:557)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.View.requestLayout(View.java:7918)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.View.requestLayout(View.java:7918)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.View.requestLayout(View.java:7918)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.View.requestLayout(View.java:7918)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.View.setBackgroundDrawable(View.java:7275)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at android.view.View.setBackgroundResource(View.java:7188)
04-10 14:59:55.331: ERROR/AndroidRuntime(263): at walk.me.Splasher$1.run(Splasher.java:35)
walk.me.Splasher$1.run(Splasher.java:35) is this line:
layout.setBackgroundResource(temp); What should I do?
但我有一個圖像在屏幕上停留了一段時間的同一線程,所以我現在想讓幾個圖像在while循環中發生變化。是否因爲我使用Thread Handler Handler? – 2011-04-10 15:36:33
使用handler.postRunnable(wallPaperRunnable,延遲),你就完成了。閱讀http://developer.android.com/resources/articles/painless-threading.html和http://developer.android.com/reference/android/os/Handler.html – 2011-04-10 15:40:09