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); }
/// <summary> /// Helper for makeAndAddView to set the position of a view /// and fill out its layout paramters. /// </summary> /// <remarks> /// Helper for makeAndAddView to set the position of a view /// and fill out its layout paramters. /// </remarks> /// <param name="child">The view to position</param> private void setUpChild(android.view.View child) { // Respect layout params that are already in the view. Otherwise // make some up... android.view.ViewGroup.LayoutParams lp = child.getLayoutParams(); if (lp == null) { lp = generateDefaultLayoutParams(); } addViewInLayout(child, 0, lp); child.setSelected(hasFocus()); // Get measure specs int childHeightSpec = android.view.ViewGroup.getChildMeasureSpec(mHeightMeasureSpec , mSpinnerPadding.top + mSpinnerPadding.bottom, lp.height); int childWidthSpec = android.view.ViewGroup.getChildMeasureSpec(mWidthMeasureSpec , mSpinnerPadding.left + mSpinnerPadding.right, lp.width); // Measure child child.measure(childWidthSpec, childHeightSpec); int childLeft; int childRight; // Position vertically based on gravity setting int childTop = mSpinnerPadding.top + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight()) / 2); int childBottom = childTop + child.getMeasuredHeight(); int width = child.getMeasuredWidth(); childLeft = 0; childRight = childLeft + width; child.layout(childLeft, childTop, childRight, childBottom); }
/// <summary><p>Measures the preferred width of each child, including its margins.</p> /// </summary> /// <param name="widthMeasureSpec">the width constraint imposed by our parent</param> /// <returns> /// an array of integers corresponding to the width of each cell, or /// column, in this row /// <hide></hide> /// </returns> internal virtual int[] getColumnsWidths(int widthMeasureSpec) { int numColumns = getVirtualChildCount(); if (mColumnWidths == null || numColumns != mColumnWidths.Length) { mColumnWidths = new int[numColumns]; } int[] columnWidths = mColumnWidths; { for (int i = 0; i < numColumns; i++) { android.view.View child = getVirtualChildAt(i); if (child != null && child.getVisibility() != GONE) { android.widget.TableRow.LayoutParams layoutParams = (android.widget.TableRow.LayoutParams )child.getLayoutParams(); if (layoutParams.span == 1) { int spec; switch (layoutParams.width) { case android.view.ViewGroup.LayoutParams.WRAP_CONTENT: { spec = getChildMeasureSpec(widthMeasureSpec, 0, android.view.ViewGroup.LayoutParams .WRAP_CONTENT); break; } case android.view.ViewGroup.LayoutParams.MATCH_PARENT: { spec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View.MeasureSpec .UNSPECIFIED); break; } default: { spec = android.view.View.MeasureSpec.makeMeasureSpec(layoutParams.width, android.view.View .MeasureSpec.EXACTLY); break; } } child.measure(spec, spec); int width = child.getMeasuredWidth() + layoutParams.leftMargin + layoutParams.rightMargin; columnWidths[i] = width; } else { columnWidths[i] = 0; } } else { columnWidths[i] = 0; } } } return(columnWidths); }
public virtual int measureContentWidth() { // The user may have specified some of the target not to be shown but we // want to measure all of them since after expansion they should fit. int oldMaxActivityCount = this.mMaxActivityCount; this.mMaxActivityCount = MAX_ACTIVITY_COUNT_UNLIMITED; int contentWidth = 0; android.view.View itemView = null; 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 = this.getCount(); { for (int i = 0; i < count; i++) { itemView = this.getView(i, itemView, null); itemView.measure(widthMeasureSpec, heightMeasureSpec); contentWidth = System.Math.Max(contentWidth, itemView.getMeasuredWidth()); } } this.mMaxActivityCount = oldMaxActivityCount; return(contentWidth); }
protected internal virtual int measureChildView(android.view.View child, int availableWidth , int childSpecHeight, int spacing) { child.measure(android.view.View.MeasureSpec.makeMeasureSpec(availableWidth, android.view.View .MeasureSpec.AT_MOST), childSpecHeight); availableWidth -= child.getMeasuredWidth(); availableWidth -= spacing; return(System.Math.Max(0, availableWidth)); }
protected internal virtual int positionChildInverse(android.view.View child, int x, int y, int contentHeight) { int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); int childTop = y + (contentHeight - childHeight) / 2; child.layout(x - childWidth, childTop, x, childTop + childHeight); return(childWidth); }
internal override void layout(int delta, bool animate_1) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = mRight - mLeft - mSpinnerPadding.left - mSpinnerPadding.right; if (mDataChanged) { handleDataChanged(); } // Handle the empty set by removing all views if (mItemCount == 0) { resetList(); return; } if (mNextSelectedPosition >= 0) { setSelectedPositionInt(mNextSelectedPosition); } recycleAllViews(); // Clear out old views removeAllViewsInLayout(); // Make selected view and position it mFirstPosition = mSelectedPosition; android.view.View sel = makeAndAddView(mSelectedPosition); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; switch (mGravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK) { case android.view.Gravity.CENTER_HORIZONTAL: { selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2); break; } case android.view.Gravity.RIGHT: { selectedOffset = childrenLeft + childrenWidth - width; break; } } sel.offsetLeftAndRight(selectedOffset); // Flush any cached views that did not get reused above mRecycler.clear(); invalidate(); checkSelectionChanged(); mDataChanged = false; mNeedSync = false; setNextSelectedPositionInt(mSelectedPosition); }
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); }
protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec ) { android.view.View child = mActivityChooserContent; // If the default action is not visible we want to be as tall as the // ActionBar so if this widget is used in the latter it will look as // a normal action button. if (mDefaultActivityButton.getVisibility() != VISIBLE) { heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(android.view.View .MeasureSpec.getSize(heightMeasureSpec), android.view.View.MeasureSpec.EXACTLY); } measureChild(child, widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(child.getMeasuredWidth(), child.getMeasuredHeight()); }
protected internal override void onLayout(bool changed, int l, int t, int r, int b) { int count = getChildCount(); { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (child.getVisibility() != GONE) { android.widget.AbsoluteLayout.LayoutParams lp = (android.widget.AbsoluteLayout.LayoutParams )child.getLayoutParams(); int childLeft = mPaddingLeft + lp.x; int childTop = mPaddingTop + lp.y; child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } } } }
/// <summary>Measure a child view to fit within cell-based formatting.</summary> /// <remarks> /// Measure a child view to fit within cell-based formatting. The child's width /// will be measured to a whole multiple of cellSize. /// <p>Sets the expandable and cellsUsed fields of LayoutParams. /// </remarks> /// <param name="child">Child to measure</param> /// <param name="cellSize">Size of one cell</param> /// <param name="cellsRemaining">Number of cells remaining that this view can expand to fill /// </param> /// <param name="parentHeightMeasureSpec">MeasureSpec used by the parent view</param> /// <param name="parentHeightPadding">Padding present in the parent view</param> /// <returns>Number of cells this child was measured to occupy</returns> internal static int measureChildForCells(android.view.View child, int cellSize, int cellsRemaining, int parentHeightMeasureSpec, int parentHeightPadding) { [email protected] lp = ([email protected] .LayoutParams)child.getLayoutParams(); int childHeightSize = android.view.View.MeasureSpec.getSize(parentHeightMeasureSpec ) - parentHeightPadding; int childHeightMode = android.view.View.MeasureSpec.getMode(parentHeightMeasureSpec ); int childHeightSpec = android.view.View.MeasureSpec.makeMeasureSpec(childHeightSize , childHeightMode); int cellsUsed = 0; if (cellsRemaining > 0) { int childWidthSpec = android.view.View.MeasureSpec.makeMeasureSpec(cellSize * cellsRemaining , android.view.View.MeasureSpec.AT_MOST); child.measure(childWidthSpec, childHeightSpec); int measuredWidth = child.getMeasuredWidth(); cellsUsed = measuredWidth / cellSize; if (measuredWidth % cellSize != 0) { cellsUsed++; } } [email protected] itemView = child is [email protected] ? ([email protected])child : null; bool expandable = !lp.isOverflowButton && itemView != null && itemView.hasText(); lp.expandable = expandable; lp.cellsUsed = cellsUsed; int targetWidth = cellsUsed * cellSize; child.measure(android.view.View.MeasureSpec.makeMeasureSpec(targetWidth, android.view.View .MeasureSpec.EXACTLY), childHeightSpec); return(cellsUsed); }
protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec ) { int count = getChildCount(); int maxHeight = 0; int maxWidth = 0; // Find out how big everyone wants to be measureChildren(widthMeasureSpec, heightMeasureSpec); { // Find rightmost and bottom-most child for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (child.getVisibility() != GONE) { int childRight; int childBottom; android.widget.AbsoluteLayout.LayoutParams lp = (android.widget.AbsoluteLayout.LayoutParams )child.getLayoutParams(); childRight = lp.x + child.getMeasuredWidth(); childBottom = lp.y + child.getMeasuredHeight(); maxWidth = System.Math.Max(maxWidth, childRight); maxHeight = System.Math.Max(maxHeight, childBottom); } } } // Account for padding too maxWidth += mPaddingLeft + mPaddingRight; maxHeight += mPaddingTop + mPaddingBottom; // Check against minimum height and width maxHeight = System.Math.Max(maxHeight, getSuggestedMinimumHeight()); maxWidth = System.Math.Max(maxWidth, getSuggestedMinimumWidth()); setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, 0), resolveSizeAndState (maxHeight, heightMeasureSpec, 0)); }
protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec ) { int count = getChildCount(); bool measureMatchParentChildren = android.view.View.MeasureSpec.getMode(widthMeasureSpec ) != android.view.View.MeasureSpec.EXACTLY || android.view.View.MeasureSpec.getMode (heightMeasureSpec) != android.view.View.MeasureSpec.EXACTLY; mMatchParentChildren.clear(); int maxHeight = 0; int maxWidth = 0; int childState = 0; { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (mMeasureAllChildren || child.getVisibility() != GONE) { measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); android.widget.FrameLayout.LayoutParams lp = (android.widget.FrameLayout.LayoutParams )child.getLayoutParams(); maxWidth = System.Math.Max(maxWidth, child.getMeasuredWidth() + lp.leftMargin + lp .rightMargin); maxHeight = System.Math.Max(maxHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchParentChildren) { if (lp.width == android.view.ViewGroup.LayoutParams.MATCH_PARENT || lp.height == android.view.ViewGroup.LayoutParams.MATCH_PARENT) { mMatchParentChildren.add(child); } } } } } // Account for padding too maxWidth += getPaddingLeftWithForeground() + getPaddingRightWithForeground(); maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground(); // Check against our minimum height and width maxHeight = System.Math.Max(maxHeight, getSuggestedMinimumHeight()); maxWidth = System.Math.Max(maxWidth, getSuggestedMinimumWidth()); // Check against our foreground's minimum height and width android.graphics.drawable.Drawable drawable = getForeground(); if (drawable != null) { maxHeight = System.Math.Max(maxHeight, drawable.getMinimumHeight()); maxWidth = System.Math.Max(maxWidth, drawable.getMinimumWidth()); } setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT )); count = mMatchParentChildren.size(); if (count > 1) { { for (int i_1 = 0; i_1 < count; i_1++) { android.view.View child = mMatchParentChildren.get(i_1); android.view.ViewGroup.MarginLayoutParams lp = (android.view.ViewGroup.MarginLayoutParams )child.getLayoutParams(); int childWidthMeasureSpec; int childHeightMeasureSpec; if (lp.width == android.view.ViewGroup.LayoutParams.MATCH_PARENT) { childWidthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(getMeasuredWidth () - getPaddingLeftWithForeground() - getPaddingRightWithForeground() - lp.leftMargin - lp.rightMargin, android.view.View.MeasureSpec.EXACTLY); } else { childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeftWithForeground () + getPaddingRightWithForeground() + lp.leftMargin + lp.rightMargin, lp.width); } if (lp.height == android.view.ViewGroup.LayoutParams.MATCH_PARENT) { childHeightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(getMeasuredHeight () - getPaddingTopWithForeground() - getPaddingBottomWithForeground() - lp.topMargin - lp.bottomMargin, android.view.View.MeasureSpec.EXACTLY); } else { childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTopWithForeground () + getPaddingBottomWithForeground() + lp.topMargin + lp.bottomMargin, lp.height ); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } } }
protected internal override void onLayout(bool changed, int left, int top, int right , int bottom) { int count = getChildCount(); int parentLeft = getPaddingLeftWithForeground(); int parentRight = right - left - getPaddingRightWithForeground(); int parentTop = getPaddingTopWithForeground(); int parentBottom = bottom - top - getPaddingBottomWithForeground(); mForegroundBoundsChanged = true; { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (child.getVisibility() != GONE) { android.widget.FrameLayout.LayoutParams lp = (android.widget.FrameLayout.LayoutParams )child.getLayoutParams(); int width = child.getMeasuredWidth(); int height = child.getMeasuredHeight(); int childLeft; int childTop; int gravity = lp.gravity; if (gravity == -1) { gravity = DEFAULT_CHILD_GRAVITY; } int layoutDirection = getResolvedLayoutDirection(); int absoluteGravity = android.view.Gravity.getAbsoluteGravity(gravity, layoutDirection ); int verticalGravity = gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK; switch (absoluteGravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK) { case android.view.Gravity.LEFT: { childLeft = parentLeft + lp.leftMargin; break; } case android.view.Gravity.CENTER_HORIZONTAL: { childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin; break; } case android.view.Gravity.RIGHT: { childLeft = parentRight - width - lp.rightMargin; break; } default: { childLeft = parentLeft + lp.leftMargin; break; } } switch (verticalGravity) { case android.view.Gravity.TOP: { childTop = parentTop + lp.topMargin; break; } case android.view.Gravity.CENTER_VERTICAL: { childTop = parentTop + (parentBottom - parentTop - height) / 2 + lp.topMargin - lp .bottomMargin; break; } case android.view.Gravity.BOTTOM: { childTop = parentBottom - height - lp.bottomMargin; break; } default: { childTop = parentTop + lp.topMargin; break; } } child.layout(childLeft, childTop, childLeft + width, childTop + height); } } } }
internal virtual int getChildWidth(android.view.View child) { return(child.getMeasuredWidth()); }
internal override void measureChildBeforeLayout(android.view.View child, int childIndex , int widthMeasureSpec, int totalWidth, int heightMeasureSpec, int totalHeight) { if (mConstrainedColumnWidths != null) { android.widget.TableRow.LayoutParams lp = (android.widget.TableRow.LayoutParams)child .getLayoutParams(); int measureMode = android.view.View.MeasureSpec.EXACTLY; int columnWidth = 0; int span = lp.span; int[] constrainedColumnWidths = mConstrainedColumnWidths; { for (int i = 0; i < span; i++) { columnWidth += constrainedColumnWidths[childIndex + i]; } } int gravity = lp.gravity; bool isHorizontalGravity = android.view.Gravity.isHorizontal(gravity); if (isHorizontalGravity) { measureMode = android.view.View.MeasureSpec.AT_MOST; } // no need to care about padding here, // ViewGroup.getChildMeasureSpec() would get rid of it anyway // because of the EXACTLY measure spec we use int childWidthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(System.Math.Max (0, columnWidth - lp.leftMargin - lp.rightMargin), measureMode); int childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin + totalHeight, lp.height); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); if (isHorizontalGravity) { int childWidth = child.getMeasuredWidth(); lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION_NEXT] = columnWidth - childWidth; int layoutDirection = getResolvedLayoutDirection(); int absoluteGravity = android.view.Gravity.getAbsoluteGravity(gravity, layoutDirection ); switch (absoluteGravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK) { case android.view.Gravity.LEFT: { // don't offset on X axis break; } case android.view.Gravity.RIGHT: { lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION] = lp.mOffset[android.widget.TableRow .LayoutParams.LOCATION_NEXT]; break; } case android.view.Gravity.CENTER_HORIZONTAL: { lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION] = lp.mOffset[android.widget.TableRow .LayoutParams.LOCATION_NEXT] / 2; break; } } } else { lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION] = lp.mOffset[android.widget.TableRow .LayoutParams.LOCATION_NEXT] = 0; } } else { // fail silently when column widths are not available base.measureChildBeforeLayout(child, childIndex, widthMeasureSpec, totalWidth, heightMeasureSpec , totalHeight); } }
public override bool flagActionItems() { java.util.ArrayList <*****@*****.**> visibleItems = mMenu .getVisibleItems(); int itemsSize = visibleItems.size(); int maxActions = mMaxItems; int widthLimit = mActionItemWidthLimit; int querySpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View .MeasureSpec.UNSPECIFIED); android.view.ViewGroup parent = (android.view.ViewGroup)mMenuView; int requiredItems = 0; int requestedItems = 0; int firstActionWidth = 0; bool hasOverflow = false; { for (int i = 0; i < itemsSize; i++) { [email protected] item = visibleItems.get(i); if (item.requiresActionButton()) { requiredItems++; } else { if (item.requestsActionButton()) { requestedItems++; } else { hasOverflow = true; } } if (mExpandedActionViewsExclusive && item.isActionViewExpanded()) { // Overflow everything if we have an expanded action view and we're // space constrained. maxActions = 0; } } } // Reserve a spot for the overflow item if needed. if (mReserveOverflow && (hasOverflow || requiredItems + requestedItems > maxActions )) { maxActions--; } maxActions -= requiredItems; android.util.SparseBooleanArray seenGroups = mActionButtonGroups; seenGroups.clear(); int cellSize = 0; int cellsRemaining = 0; if (mStrictWidthLimit) { cellsRemaining = widthLimit / mMinCellSize; int cellSizeRemaining = widthLimit % mMinCellSize; cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining; } { // Flag as many more requested items as will fit. for (int i_1 = 0; i_1 < itemsSize; i_1++) { [email protected] item = visibleItems.get(i_1); if (item.requiresActionButton()) { android.view.View v = getItemView(item, mScrapActionButtonView, parent); if (mScrapActionButtonView == null) { mScrapActionButtonView = v; } if (mStrictWidthLimit) { cellsRemaining -= [email protected] (v, cellSize, cellsRemaining, querySpec, 0); } else { v.measure(querySpec, querySpec); } int measuredWidth = v.getMeasuredWidth(); widthLimit -= measuredWidth; if (firstActionWidth == 0) { firstActionWidth = measuredWidth; } int groupId = item.getGroupId(); if (groupId != 0) { seenGroups.put(groupId, true); } item.setIsActionButton(true); } else { if (item.requestsActionButton()) { // Items in a group with other items that already have an action slot // can break the max actions rule, but not the width limit. int groupId = item.getGroupId(); bool inGroup = seenGroups.get(groupId); bool isAction = (maxActions > 0 || inGroup) && widthLimit > 0 && (!mStrictWidthLimit || cellsRemaining > 0); if (isAction) { android.view.View v = getItemView(item, mScrapActionButtonView, parent); if (mScrapActionButtonView == null) { mScrapActionButtonView = v; } if (mStrictWidthLimit) { int cells = [email protected](v, cellSize , cellsRemaining, querySpec, 0); cellsRemaining -= cells; if (cells == 0) { isAction = false; } } else { v.measure(querySpec, querySpec); } int measuredWidth = v.getMeasuredWidth(); widthLimit -= measuredWidth; if (firstActionWidth == 0) { firstActionWidth = measuredWidth; } if (mStrictWidthLimit) { isAction &= widthLimit >= 0; } else { // Did this push the entire first item past the limit? isAction &= widthLimit + firstActionWidth > 0; } } if (isAction && groupId != 0) { seenGroups.put(groupId, true); } else { if (inGroup) { // We broke the width limit. Demote the whole group, they all overflow now. seenGroups.put(groupId, false); { for (int j = 0; j < i_1; j++) { [email protected] areYouMyGroupie = visibleItems.get(j); if (areYouMyGroupie.getGroupId() == groupId) { // Give back the action slot if (areYouMyGroupie.isActionButton()) { maxActions++; } areYouMyGroupie.setIsActionButton(false); } } } } } if (isAction) { maxActions--; } item.setIsActionButton(isAction); } } } } return(true); }
protected internal override void onLayout(bool changed, int left, int top, int right , int bottom) { if (!mFormatItems) { base.onLayout(changed, left, top, right, bottom); return; } int childCount = getChildCount(); int midVertical = (top + bottom) / 2; int dividerWidth = getDividerWidth(); int overflowWidth = 0; int nonOverflowWidth = 0; int nonOverflowCount = 0; int widthRemaining = right - left - getPaddingRight() - getPaddingLeft(); bool hasOverflow = false; { for (int i = 0; i < childCount; i++) { android.view.View v = getChildAt(i); if (v.getVisibility() == GONE) { continue; } [email protected] p = ([email protected] .LayoutParams)v.getLayoutParams(); if (p.isOverflowButton) { overflowWidth = v.getMeasuredWidth(); if (hasDividerBeforeChildAt(i)) { overflowWidth += dividerWidth; } int height = v.getMeasuredHeight(); int r = getWidth() - getPaddingRight() - p.rightMargin; int l = r - overflowWidth; int t = midVertical - (height / 2); int b = t + height; v.layout(l, t, r, b); widthRemaining -= overflowWidth; hasOverflow = true; } else { int size = v.getMeasuredWidth() + p.leftMargin + p.rightMargin; nonOverflowWidth += size; widthRemaining -= size; if (hasDividerBeforeChildAt(i)) { nonOverflowWidth += dividerWidth; } nonOverflowCount++; } } } if (childCount == 1 && !hasOverflow) { // Center a single child android.view.View v = getChildAt(0); int width = v.getMeasuredWidth(); int height = v.getMeasuredHeight(); int midHorizontal = (right - left) / 2; int l = midHorizontal - width / 2; int t = midVertical - height / 2; v.layout(l, t, l + width, t + height); return; } int spacerCount = nonOverflowCount - (hasOverflow ? 0 : 1); int spacerSize = System.Math.Max(0, spacerCount > 0 ? widthRemaining / spacerCount : 0); int startLeft = getPaddingLeft(); { for (int i_1 = 0; i_1 < childCount; i_1++) { android.view.View v = getChildAt(i_1); [email protected] lp = ([email protected] .LayoutParams)v.getLayoutParams(); if (v.getVisibility() == GONE || lp.isOverflowButton) { continue; } startLeft += lp.leftMargin; int width = v.getMeasuredWidth(); int height = v.getMeasuredHeight(); int t = midVertical - height / 2; v.layout(startLeft, t, startLeft + width, t + height); startLeft += width + lp.rightMargin + spacerSize; } } }
internal override void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec ) { if (android.view.View.MeasureSpec.getMode(widthMeasureSpec) == android.view.View. MeasureSpec.UNSPECIFIED) { base.measureHorizontal(widthMeasureSpec, heightMeasureSpec); return; } // First, measure with no constraint int unspecifiedWidth = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View .MeasureSpec.UNSPECIFIED); mImposedTabsHeight = -1; base.measureHorizontal(unspecifiedWidth, heightMeasureSpec); int extraWidth = getMeasuredWidth() - android.view.View.MeasureSpec.getSize(widthMeasureSpec ); if (extraWidth > 0) { int count = getChildCount(); int childCount = 0; { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } childCount++; } } if (childCount > 0) { if (mImposedTabWidths == null || mImposedTabWidths.Length != count) { mImposedTabWidths = new int[count]; } { for (int i_1 = 0; i_1 < count; i_1++) { android.view.View child = getChildAt(i_1); if (child.getVisibility() == GONE) { continue; } int childWidth = child.getMeasuredWidth(); int delta = extraWidth / childCount; int newWidth = System.Math.Max(0, childWidth - delta); mImposedTabWidths[i_1] = newWidth; // Make sure the extra width is evenly distributed, no int division remainder extraWidth -= childWidth - newWidth; // delta may have been clamped childCount--; mImposedTabsHeight = System.Math.Max(mImposedTabsHeight, child.getMeasuredHeight( )); } } } } // Measure again, this time with imposed tab widths and respecting initial spec request base.measureHorizontal(widthMeasureSpec, heightMeasureSpec); }