在项目开发中,遇到了 当view为gone时 测量高度一直为0,解决办法:
mView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener(){
@Override
public void onGlobalLayout() {
// gets called after layout has been done but before display
// so we can get the height then hide the view
mHeight = mView.getHeight();
mView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
mView.setVisibility(View.GONE);
}
});
参考: https://stackoverflow.com/questions/18277028/getheight-for-view-which-has-visibility-gone