2012-06-17 26 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

onVisibilityChangedあなたが名前から期待するものではありませんもっとコードを投稿できますか?すべての重い作業がどこで行われたかを知る必要があります。私のライブ壁紙では、画面の回転中にonSurfaceChangedとonVisibilityChangedの両方が呼び出されます。また、LogCatでオリエンテーションの変更中に「タイムアウトが壁紙を待つのを待っています」のようなものを確認してください。応答のための – Ole

答えて

1

、宣言:

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

あなたonSurfaceChanged - メソッドは、マニフェストにconfigChanges属性を宣言する場合にのみ呼び出されます。あなたの第二の問題について

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

おかげで、私はこれに私のライブ壁紙のサービスを変更します。 <意図-フィルタ> <アクションアンドロイド:名= "android.service.wallpaper.WallpaperService" /> <メタデータ アンドロイド:名= "android.service.wallpaper" アンドロイド: – Denizen

+0

私の問題は、常に20個の長方形を初期化して、40個ほどのif文を持っているということです。それらをまねする。パフォーマンスが低下するアニメートを行ってもif文が常にチェックされています – Denizen

+0

上記の答えはライブ壁紙には適用されませんが、SurfaceViewを使用するアプリケーションには適用されません。したがって、configChanges属性を設定することは何もしません。 – Ole

関連する問題