I have a layout with some Views that I need to change size depending on some parameters, that depend on width of the View. The width is set to "match_parent". So when I try to get the width it returns 0. Here is what I have tried so far:
mask.getWidth();
mask.getLayoutParams().width
ViewTreeObserver vto = mask.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mask.getViewTreeObserver().removeGlobalOnLayoutListener(this); int width = mask.getMeasuredWidth(); } });
So my question is how do I get the width in this situation? Thank you.