@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize;
        int heightSize;

        final int mPaddingLeft = getPaddingLeft();
        final int mPaddingTop = getPaddingTop();
        final int mPaddingRight = getPaddingRight();
        final int mPaddingBottom = getPaddingBottom();

        mSpinnerPadding.left = mPaddingLeft > mSelectionLeftPadding ? mPaddingLeft
                : mSelectionLeftPadding;
        mSpinnerPadding.top = mPaddingTop > mSelectionTopPadding ? mPaddingTop
                : mSelectionTopPadding;
        mSpinnerPadding.right = mPaddingRight > mSelectionRightPadding ? mPaddingRight
                : mSelectionRightPadding;
        mSpinnerPadding.bottom = mPaddingBottom > mSelectionBottomPadding ? mPaddingBottom
                : mSelectionBottomPadding;

        if (mDataChanged) {
            handleDataChanged();
        }

        int preferredHeight = 0;
        int preferredWidth = 0;
        boolean needsMeasuring = true;

        int selectedPosition = getSelectedItemPosition();
        if (selectedPosition >= 0 && mAdapter != null && selectedPosition < mAdapter.getCount()) {
            // Try looking in the recycler. (Maybe we were measured once already)
            View view = mRecycler.get(selectedPosition);
            if (view == null) {
                // Make a new one
                view = mAdapter.getView(selectedPosition, null, this);
            }

            if (view != null) {
                // Put in recycler for re-measuring and/or layout
                mRecycler.put(selectedPosition, view);
            }

            if (view != null) {
                if (view.getLayoutParams() == null) {
                    mBlockLayoutRequests = true;
                    view.setLayoutParams(generateDefaultLayoutParams());
                    mBlockLayoutRequests = false;
                }
                measureChild(view, widthMeasureSpec, heightMeasureSpec);

                preferredHeight = getChildHeight(view) + mSpinnerPadding.top + mSpinnerPadding.bottom;
                preferredWidth = getChildWidth(view) + mSpinnerPadding.left + mSpinnerPadding.right;

                needsMeasuring = false;
            }
        }

        if (needsMeasuring) {
            // No views -- just use padding
            preferredHeight = mSpinnerPadding.top + mSpinnerPadding.bottom;
            if (widthMode == MeasureSpec.UNSPECIFIED) {
                preferredWidth = mSpinnerPadding.left + mSpinnerPadding.right;
            }
        }

        preferredHeight = Math.max(preferredHeight, getSuggestedMinimumHeight());
        preferredWidth = Math.max(preferredWidth, getSuggestedMinimumWidth());

        if (IS_HONEYCOMB) {
            heightSize = resolveSizeAndState(preferredHeight, heightMeasureSpec, 0);
            widthSize = resolveSizeAndState(preferredWidth, widthMeasureSpec, 0);
        } else {
            heightSize = resolveSize(preferredHeight, heightMeasureSpec);
            widthSize = resolveSize(preferredWidth, widthMeasureSpec);
        }

        setMeasuredDimension(widthSize, heightSize);
        mHeightMeasureSpec = heightMeasureSpec;
        mWidthMeasureSpec = widthMeasureSpec;
    }
@ Override protected void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) { int widthMode = MeasureSpec . getMode ( widthMeasureSpec ) ; int widthSize ; int heightSize ; final int mPaddingLeft = getPaddingLeft ( ) ; final int mPaddingTop = getPaddingTop ( ) ; final int mPaddingRight = getPaddingRight ( ) ; final int mPaddingBottom = getPaddingBottom ( ) ; mSpinnerPadding . left = mPaddingLeft > mSelectionLeftPadding ? mPaddingLeft : mSelectionLeftPadding ; mSpinnerPadding . top = mPaddingTop > mSelectionTopPadding ? mPaddingTop : mSelectionTopPadding ; mSpinnerPadding . right = mPaddingRight > mSelectionRightPadding ? mPaddingRight : mSelectionRightPadding ; mSpinnerPadding . bottom = mPaddingBottom > mSelectionBottomPadding ? mPaddingBottom : mSelectionBottomPadding ; if ( mDataChanged ) { handleDataChanged ( ) ; } int preferredHeight = 0 ; int preferredWidth = 0 ; boolean needsMeasuring = true ; int selectedPosition = getSelectedItemPosition ( ) ; if ( selectedPosition >= 0 && mAdapter != null && selectedPosition < mAdapter . getCount ( ) ) { View view = mRecycler . get ( selectedPosition ) ; if ( view == null ) { view = mAdapter . getView ( selectedPosition , null , this ) ; } if ( view != null ) { mRecycler . put ( selectedPosition , view ) ; } if ( view != null ) { if ( view . getLayoutParams ( ) == null ) { mBlockLayoutRequests = true ; view . setLayoutParams ( generateDefaultLayoutParams ( ) ) ; mBlockLayoutRequests = false ; } measureChild ( view , widthMeasureSpec , heightMeasureSpec ) ; preferredHeight = getChildHeight ( view ) + mSpinnerPadding . top + mSpinnerPadding . bottom ; preferredWidth = getChildWidth ( view ) + mSpinnerPadding . left + mSpinnerPadding . right ; needsMeasuring = false ; } } if ( needsMeasuring ) { preferredHeight = mSpinnerPadding . top + mSpinnerPadding . bottom ; if ( widthMode == MeasureSpec . UNSPECIFIED ) { preferredWidth = mSpinnerPadding . left + mSpinnerPadding . right ; } } preferredHeight = Math . max ( preferredHeight , getSuggestedMinimumHeight ( ) ) ; preferredWidth = Math . max ( preferredWidth , getSuggestedMinimumWidth ( ) ) ; if ( IS_HONEYCOMB ) { heightSize = resolveSizeAndState ( preferredHeight , heightMeasureSpec , 0 ) ; widthSize = resolveSizeAndState ( preferredWidth , widthMeasureSpec , 0 ) ; } else { heightSize = resolveSize ( preferredHeight , heightMeasureSpec ) ; widthSize = resolveSize ( preferredWidth , widthMeasureSpec ) ; } setMeasuredDimension ( widthSize , heightSize ) ; mHeightMeasureSpec = heightMeasureSpec ; mWidthMeasureSpec = widthMeasureSpec ; }
@see android.view.View#measure(int, int)

Figure out the dimensions of this Spinner. The width comes from
the widthMeasureSpec as Spinnners can't have their width set to
UNSPECIFIED. The height is based on the height of the selected item
plus padding.