2012-02-05 18 views

回答

4

奇怪的是,我得到當天重用一個答案,我讓它:

您可以設置在視圖樹全球佈局聽衆在onResume(),做你的diddling在那裏。

final ViewTreeObserver vto = myView.getViewTreeObserver(); 
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 

    public void onGlobalLayout() { 
     // do layout tweaking based on measurements 

     // remove the listener... or we'll be doing this a lot. 
     vto.removeGlobalOnLayoutListener(this); 
    } 
} 
+4

我不得不使用'vto.isAlive()'和'調用getViewTreeObserver()'再次,否則用'java.lang.IllegalStateException崩潰:這ViewTreeObserver不alive'。不管怎樣,謝謝。 – 2012-02-05 20:56:15

+0

啊!很高興發現並很高興它有幫助。祝你好運。 – 2012-02-05 20:57:59

+0

@AndreyNovikov你能證明你是如何做到的嗎? – Danpe 2016-03-08 18:27:51

相關問題