internal virtual int measureContentWidth(android.widget.SpinnerAdapter adapter, android.graphics.drawable.Drawable background) { if (adapter == null) { return 0; } int width = 0; android.view.View itemView = null; int itemType = 0; int widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View .MeasureSpec.UNSPECIFIED); int heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View .MeasureSpec.UNSPECIFIED); // Make sure the number of items we'll measure is capped. If it's a huge data set // with wildly varying sizes, oh well. int start = System.Math.Max(0, getSelectedItemPosition()); int end = System.Math.Min(adapter.getCount(), start + MAX_ITEMS_MEASURED); int count = end - start; start = System.Math.Max(0, start - (MAX_ITEMS_MEASURED - count)); { for (int i = start; i < end; i++) { int positionType = adapter.getItemViewType(i); if (positionType != itemType) { itemType = positionType; itemView = null; } itemView = adapter.getView(i, itemView, this); if (itemView.getLayoutParams() == null) { itemView.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup .LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); } itemView.measure(widthMeasureSpec, heightMeasureSpec); width = System.Math.Max(width, itemView.getMeasuredWidth()); } } // Add background padding to measured width if (background != null) { background.getPadding(mTempRect); width += mTempRect.left + mTempRect.right; } return width; }
/// <summary> /// Supply a Drawable that is to be rendered on top of all of the child /// views in the frame layout. /// </summary> /// <remarks> /// Supply a Drawable that is to be rendered on top of all of the child /// views in the frame layout. Any padding in the Drawable will be taken /// into account by ensuring that the children are inset to be placed /// inside of the padding area. /// </remarks> /// <param name="drawable">The Drawable to be drawn on top of the children.</param> /// <attr>ref android.R.styleable#FrameLayout_foreground</attr> public virtual void setForeground(android.graphics.drawable.Drawable drawable) { if (mForeground != drawable) { if (mForeground != null) { mForeground.setCallback(null); unscheduleDrawable(mForeground); } mForeground = drawable; mForegroundPaddingLeft = 0; mForegroundPaddingTop = 0; mForegroundPaddingRight = 0; mForegroundPaddingBottom = 0; if (drawable != null) { setWillNotDraw(false); drawable.setCallback(this); if (drawable.isStateful()) { drawable.setState(getDrawableState()); } if (mForegroundGravity == android.view.Gravity.FILL) { android.graphics.Rect padding = new android.graphics.Rect(); if (drawable.getPadding(padding)) { mForegroundPaddingLeft = padding.left; mForegroundPaddingTop = padding.top; mForegroundPaddingRight = padding.right; mForegroundPaddingBottom = padding.bottom; } } } else { setWillNotDraw(true); } requestLayout(); invalidate(); } }