protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
var widthMode = MeasureSpec.GetMode(widthMeasureSpec);
var lockedExpanded = widthMode == MeasureSpecMode.Exactly;
FillViewport = lockedExpanded;
var childCount = _tabLayout.ChildCount;
if (childCount > 1 && (widthMode == MeasureSpecMode.Exactly || widthMode == MeasureSpecMode.AtMost))
{
if (childCount > 2)
_maxTabWidth = (int)(MeasureSpec.GetSize(widthMeasureSpec) * 0.4f);
else
_maxTabWidth = MeasureSpec.GetSize(widthMeasureSpec) / 2;
}
else
_maxTabWidth = -1;
var oldWidth = MeasuredWidth;
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
var newWidth = MeasuredWidth;
if (lockedExpanded && oldWidth != newWidth)
CurrentItem = _selectedTabIndex;
}