0
我需要知道我的Activity
ASAP onResume
之後的某些視圖的正確寬度,高度和位置。我可以在哪裏放置這段代碼?如何在我的活動中測量所有視圖時勾住片刻?
我需要知道我的Activity
ASAP onResume
之後的某些視圖的正確寬度,高度和位置。我可以在哪裏放置這段代碼?如何在我的活動中測量所有視圖時勾住片刻?
奇怪的是,我得到當天重用一個答案,我讓它:
您可以設置在視圖樹全球佈局聽衆在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);
}
}
我不得不使用'vto.isAlive()'和'調用getViewTreeObserver()'再次,否則用'java.lang.IllegalStateException崩潰:這ViewTreeObserver不alive'。不管怎樣,謝謝。 – 2012-02-05 20:56:15
啊!很高興發現並很高興它有幫助。祝你好運。 – 2012-02-05 20:57:59
@AndreyNovikov你能證明你是如何做到的嗎? – Danpe 2016-03-08 18:27:51