/// <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); }
internal override int getChildrenSkipCount(android.view.View child, int index) { android.widget.TableRow.LayoutParams layoutParams = (android.widget.TableRow.LayoutParams )child.getLayoutParams(); // when the span is 1 (default), we need to skip 0 child return(layoutParams.span - 1); }
private void mapIndexAndColumns() { if (mColumnToChildIndex == null) { int virtualCount = 0; int count = getChildCount(); mColumnToChildIndex = new android.util.SparseIntArray(); android.util.SparseIntArray columnToChild = mColumnToChildIndex; { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); android.widget.TableRow.LayoutParams layoutParams = (android.widget.TableRow.LayoutParams )child.getLayoutParams(); if (layoutParams.column >= virtualCount) { virtualCount = layoutParams.column; } { for (int j = 0; j < layoutParams.span; j++) { columnToChild.put(virtualCount++, i); } } } } mNumColumns = virtualCount; } }
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); } }