許多元件初始時均由於資料尚未封裝加上還未呈現, 所以取回的常是 0, 若需要知道元件真正呈現時的長寬, 則可透過下事件方式取得(gvView 表示你要取得的元件)
ViewTreeObserver observer = gvView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (wHeight != gvView.getMeasuredHeight()) { wHeight = gvView.getMeasuredHeight(); } } });