The code syntax below should properly solve your problem.
TabLayout tabLayout = ...;
if (tabLayout.getMeasuredHeight() == 0) tabLayout.measure(View.MeasureSpec.UNDEFINED, View.MeasureSpec.UNDEFINED);
int tabLayoutHeight = tabLayout.getMeasuredHeight();