2012-06-17 137 views
5

我目前正在研究一個非常密集的活動壁紙,並且不能很好地處理屏幕旋轉。動態壁紙屏幕旋轉

事實上,壁紙被破壞,並顯示一個空白的屏幕,而無需調用onSurfaceChanged!

這是我有onSurfaceChanged方法中:

@Override 
    public void onSurfaceChanged(SurfaceHolder holder, int format, 
      int width, int height) { 
     // TODO Auto-generated method stub 
     super.onSurfaceChanged(holder, format, width, height); 

     mRatio = (float) width/height; 
     if (mRatio > 1) { 
      orientation = 0; 
     } 
     if (mRatio < 1) { 
      orientation = 1; 
     } 
     setRunning(true); 
     Log.i(TAG, "Screen Rotation..."); 
     mHandle.post(r); 
    } 

我肯定這種方法不會被調用,因爲沒有日誌消息。

爲什麼會發生這種情況,以及處理屏幕旋轉的一些技巧是什麼? 難道是我的動態壁紙是如此密集的虛空不能被稱爲?

此外,onVisibilityChanged不叫,以及當我打開模擬器的應用程序,也沒有日誌消息:

@Override 
    public void onVisibilityChanged(boolean visible) { 
     // TODO Auto-generated method stub 
     super.onVisibilityChanged(visible); 
     if (visible) { 
      setRunning(true); 
      Log.i(TAG, "Visible..."); 
      mHandle.postDelayed(r, 2000); 
     } else { 
      setRunning(false); 
      Log.i(TAG, "Invisible..."); 
      mHandle.removeCallbacks(r); 
     } 
    } 
+0

你能發佈更多的代碼嗎?需要知道所有繁重的工作在哪裏完成。在我的動態壁紙中,onSurfaceChanged和onVisibilityChanged在屏幕旋轉期間被調用。此外,在方向更改期間,請檢查LogCat中的「超時等待牆紙偏移」。 – Ole

回答

1

在您的清單,聲明:

<activity android:name=".YourActivityName" 
       android:configChanges="keyboardHidden|orientation" 
    </activity> 

onSurfaceChanged - 方法僅在聲明configChanges-屬性時才被調用!

關於你提到的第二個問題:onVisibilityChanged不是你們想從名字的期望:

Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE). Note that this tells you whether or not your window is being made visible to the window manager; this does not tell you whether or not your window is obscured by other windows on the screen, even if it is itself visible.

你需要檢查你的應用程序是否通過onPause()是「看得見」的用戶和onResume()

+0

感謝您的答覆,我改變了我的生活壁紙服務這樣:<服務 機器人:名字= 「JuiceBarsWPService。」 機器人:權限= 「android.permission.BIND_WALLPAPER」 機器人:configChanges = 「keyboardHidden |方向」> <意圖濾波器> <操作機器人:名稱= 「android.service.wallpaper.WallpaperService」/> <元數據 機器人:名稱= 「android.service.wallpaper」 機器人:resource =「@ xml/mylwp」/> - 它不起作用:( – Denizen

+0

我的問題是,我不斷初始化20個矩形,並有40左右,如果語句爲爲他們提供樂趣。 if語句即使在動畫顯示性能下降時也會不斷被檢查 – Denizen

+0

上述答案不適用於動態壁紙,而適用於使用SurfaceView的應用程序。所以設置configChanges屬性將不會執行任何操作。請發佈更多的代碼.. – Ole