public override void MeasureChild(Android.Views.View child, int widthUsed, int heightUsed) { int columnPosition = GetPosition(child); // Get cached width size of column and cell int cacheWidth = mCellLayoutManager.GetCacheWidth(mYPosition, columnPosition); int columnCacheWidth = mColumnHeaderLayoutManager.GetCacheWidth(columnPosition); // Already each of them is same width size. if (cacheWidth != -1 && cacheWidth == columnCacheWidth) { // Control whether we need to set width or not. if (child.MeasuredWidth != cacheWidth) { TableViewUtils.SetWidth(child, cacheWidth); } } else { Android.Views.View columnHeaderChild = mColumnHeaderLayoutManager.FindViewByPosition(columnPosition); if (columnHeaderChild == null) { return; } // Need to calculate which one has the broadest width ? FitWidthSize(child, mYPosition, columnPosition, cacheWidth, columnCacheWidth, columnHeaderChild); } // Control all of the rows which has same column position. if (ShouldFitColumns(columnPosition, mYPosition)) { if (mLastDx < 0) { Log.Warn(LogTag, "x: " + columnPosition + " y: " + mYPosition + " fitWidthSize " + "left side "); mCellLayoutManager.FitWidthSize(columnPosition, true); } else { mCellLayoutManager.FitWidthSize(columnPosition, false); Log.Warn(LogTag, "x: " + columnPosition + " y: " + mYPosition + " fitWidthSize " + "right side"); } mNeedFitForVerticalScroll = false; } // It need to be cleared to prevent unnecessary calculation. mNeedFitForHorizontalScroll = false; }
private void FitWidthSize(Android.Views.View child, int row, int column, int cellWidth, int columnHeaderWidth, Android.Views.View columnHeaderChild) { if (cellWidth == -1) { // Alternatively, TableViewUtils.getWidth(child); cellWidth = child.MeasuredWidth; } if (columnHeaderWidth == -1) { // Alternatively, TableViewUtils.getWidth(columnHeaderChild) columnHeaderWidth = columnHeaderChild.MeasuredWidth; } if (cellWidth != 0) { if (columnHeaderWidth > cellWidth) { cellWidth = columnHeaderWidth; } else { if (cellWidth > columnHeaderWidth) { columnHeaderWidth = cellWidth; } } // Control whether column header needs to be change interns of width if (columnHeaderWidth != columnHeaderChild.Width) { TableViewUtils.SetWidth(columnHeaderChild, columnHeaderWidth); mNeedFitForVerticalScroll = true; mNeedFitForHorizontalScroll = true; } // Set the value to cache it for column header. mColumnHeaderLayoutManager.SetCacheWidth(column, columnHeaderWidth); } // Set the width value to cache it for cell . TableViewUtils.SetWidth(child, cellWidth); mCellLayoutManager.SetCacheWidth(row, column, cellWidth); }
public override void MeasureChild(Android.Views.View child, int widthUsed, int heightUsed) { // If has fixed width is true, than calculation of the column width is not necessary. if (mTableView.HasFixedWidth()) { base.MeasureChild(child, widthUsed, heightUsed); return; } int position = GetPosition(child); int cacheWidth = GetCacheWidth(position); // If the width value of the cell has already calculated, then set the value if (cacheWidth != -1) { TableViewUtils.SetWidth(child, cacheWidth); } else { base.MeasureChild(child, widthUsed, heightUsed); } }
private void Fit2(int xPosition, int yPosition, int columnCachedWidth, Android.Views.View column, ColumnLayoutManager childLayoutManager) { int cellCacheWidth = GetCacheWidth(yPosition, xPosition); Android.Views.View cell = childLayoutManager.FindViewByPosition(xPosition); // Control whether the cell needs to be fitted by column header or not. if (cell != null) { if (cellCacheWidth != columnCachedWidth || mNeedSetLeft) { // This is just for setting width value if (cellCacheWidth != columnCachedWidth) { cellCacheWidth = columnCachedWidth; TableViewUtils.SetWidth(cell, cellCacheWidth); SetCacheWidth(yPosition, xPosition, cellCacheWidth); } // The left & right values of Column header can be considered. Because this // method will be worked // after drawing process of main thread. if (column.Left != cell.Left || column.Right != cell.Right) { // TODO: + 1 is for decoration item. It should be gotten from a generic // method of layoutManager // Set right & left values cell.Left = column.Left; cell.Right = column.Right + 1; childLayoutManager.LayoutDecoratedWithMargins(cell, cell.Left, cell.Top, cell.Right, cell.Bottom); mNeedSetLeft = true; } } } }
private int Fit(int xPosition, int yPosition, int left, int right, int columnCachedWidth) { CellRecyclerView child = (CellRecyclerView)FindViewByPosition(yPosition); if (child != null) { ColumnLayoutManager childLayoutManager = (ColumnLayoutManager)child.GetLayoutManager(); int cellCacheWidth = GetCacheWidth(yPosition, xPosition); Android.Views.View cell = childLayoutManager.FindViewByPosition(xPosition); // Control whether the cell needs to be fitted by column header or not. if (cell != null) { if (cellCacheWidth != columnCachedWidth || mNeedSetLeft) { // This is just for setting width value if (cellCacheWidth != columnCachedWidth) { cellCacheWidth = columnCachedWidth; TableViewUtils.SetWidth(cell, cellCacheWidth); SetCacheWidth(yPosition, xPosition, cellCacheWidth); } // Even if the cached values are same, the left & right value wouldn't change. // mNeedSetLeft & the below lines for it. if (left != IgnoreLeft && cell.Left != left) { // Calculate scroll distance int scrollX = Math.Max(cell.Left, left) - Math.Min(cell.Left, left); // Update its left cell.Left = left; int offset = mHorizontalListener.GetScrollPositionOffset(); // It shouldn't be scroll horizontally and the problem is gotten just for // first visible item. if (offset > 0 && xPosition == childLayoutManager.FindFirstVisibleItemPosition() && mCellRecyclerView.ScrollState != RecyclerView.ScrollStateIdle) { int scrollPosition = mHorizontalListener.GetScrollPosition(); offset = mHorizontalListener.GetScrollPositionOffset() + scrollX; // Update scroll position offset value mHorizontalListener.SetScrollPositionOffset(offset); // Scroll considering to the desired value. childLayoutManager.ScrollToPositionWithOffset(scrollPosition, offset); } } if (cell.Width != cellCacheWidth) { if (left != IgnoreLeft) { // TODO: + 1 is for decoration item. It should be gotten from a // generic method of layoutManager // Set right right = cell.Left + cellCacheWidth + 1; cell.Right = right; childLayoutManager.LayoutDecoratedWithMargins(cell, cell.Left, cell.Top, cell.Right, cell.Bottom); } mNeedSetLeft = true; } } } } return(right); }