question: private int calculateLayoutWidth ( int widthSize , int mode ) { initResourcesIfNecessary ( ) ; int width = widthSize ; int maxLength = getMaxTextLength ( ) ; if ( maxLength > 0 ) { float textWidth = FloatMath . ceil ( Layout . getDesiredWidth ( "0" , itemsPaint ) ) ; itemsWidth = ( int ) ( maxLength * textWidth ) ; } else { itemsWidth = 0 ; } itemsWidth += ADDITIONAL_ITEMS_SPACE ; labelWidth = 0 ; if ( label != null && label . length ( ) > 0 ) { labelWidth = ( int ) FloatMath . ceil ( Layout . getDesiredWidth ( label , valuePaint ) ) ; } boolean recalculate = false ; if ( mode == MeasureSpec . EXACTLY ) { width = widthSize ; recalculate = true ; } else { width = itemsWidth + labelWidth + 2 * PADDING ; if ( labelWidth > 0 ) { width += LABEL_OFFSET ; } width = Math . max ( width , getSuggestedMinimumWidth ( ) ) ; if ( mode == MeasureSpec . AT_MOST && widthSize < width ) { width = widthSize ; recalculate = true ; } } if ( recalculate ) { int pureWidth = width - LABEL_OFFSET - 2 * PADDING ; if ( pureWidth <= 0 ) { itemsWidth = labelWidth = 0 ; } if ( labelWidth > 0 ) { double newWidthItems = ( double ) itemsWidth * pureWidth / ( itemsWidth + labelWidth ) ; itemsWidth = ( int ) newWidthItems ; labelWidth = pureWidth - itemsWidth ; } else { itemsWidth = pureWidth + LABEL_OFFSET ; } } if ( itemsWidth > 0 ) { createLayouts ( itemsWidth , labelWidth ) ; } return width ; }
target:  Calculates control width and creates text layouts