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; }
private int measureContentWidth(android.widget.ListAdapter adapter) { // Menus don't tend to be long, so this is more sane than it looks. 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); int count = adapter.getCount(); { for (int i = 0; i < count; i++) { int positionType = adapter.getItemViewType(i); if (positionType != itemType) { itemType = positionType; itemView = null; } if (mMeasureParent == null) { mMeasureParent = new android.widget.FrameLayout(mContext); } itemView = adapter.getView(i, itemView, mMeasureParent); itemView.measure(widthMeasureSpec, heightMeasureSpec); width = System.Math.Max(width, itemView.getMeasuredWidth()); } } return width; }