How to get programmatically created RelativeLayout's height after adding all the views in it (i.e., when it really can be measured)? I programmatically created Buttons that should be children for that RL, set their margins and alignment, added them to the RL, so RL's height can be measured. Ordinary rl.getHeight() returns 0. I used this code:
rl.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int rlHeight=rl.getMeasuredHeight();
And on Nexus 5 (API 23) everything's ok, but on the other device with API 17 (as I remember, 4.2 or something) it throws NPE. What to do?
P.S. OnGlobalLayoutListener and OnPreDrawListener are not ok, because I need the height to be measured before calling setParams(...) and adding the RL to outer layout.