3

以前、私はHeight of statusbar?(and also Tiltebar) ここで見つけるためにこのスニペットを見ました:

Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;

昨日、このスニペットをクラスで使用しようとしたAsyncTaskので、アクティビティのインスタンスをアクティビティのAsyncTaskクラスに送信しますonCreate

LongOperation loper = new LongOperation(this, vg, vArray, hintsArray,x_positionArray, y_positionArray);//Here `this` refers to current Activity
loper.execute("YES");

AsynkTaskクラスのdoInBackgroundでは、次のことだけを行いました。

Thread.sleep(3000); 

そして、onPostExecuteメソッドでは、ステータスバーとタイトルバーの高さを計算するために上記のコードをコピーしますが、logcatに有用なログがないため、アプリがクラッシュします。次に、次のような行にコメントします。

Rect rectgle = new Rect();
    Window window = activity.getWindow();
//  window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
//  int StatusBarHeight= rectgle.top;
    contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT)
            .getTop();
//  int TitleBarHeight= contentViewTop - StatusBarHeight;

とアプリは正常に動作します。

window.getDecorView()。getWindowVisibleDisplayFrame(rectgle);

アプリがクラッシュする原因になりますが、理由はわかりません。何か間違ったことをしましたか?

4

1 に答える 1

0

Android 2.3.3でアプリを実行している場合は、アプリがクラッシュする可能性があります。この方法は壊れているため、このソリューションが役立つ場合があります。

お役に立てれば :)

于 2013-01-05T09:02:31.690 に答える