在UI建立後取得UI長寬
一般可能會寫在
view.post()
裡面
但是手機效能太好的時候可能post先執行了view雖然在記憶體產生了卻還沒畫出來這時候長寬就會是0
下列方法可以確定view已經畫完:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//scrollView_vx、graphView_vx是我建立的view
scrollView_vx = scrollView.getWidth();
graphView_vx = mGraphView.getWidth();
}
View: @Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (changed) {
//mContent 是我建立的物件
mContent.width = right-left;
mContent.height = bottom-top;
}
}
留言
張貼留言