private void FitSize2(int position, bool scrollingLeft, int columnHeaderScrollPosition, int columnHeaderOffset, int columnHeaderFirstItem) { int columnCacheWidth = mColumnHeaderLayoutManager.GetCacheWidth(position); Android.Views.View column = mColumnHeaderLayoutManager.FindViewByPosition(position); if (column != null) { // Loop for all rows which are visible. for (int j = FindFirstVisibleItemPosition(); j < FindLastVisibleItemPosition() + 1; j++) { // Get CellRowRecyclerView CellRecyclerView child = (CellRecyclerView)FindViewByPosition(j); if (child != null) { ColumnLayoutManager childLayoutManager = (ColumnLayoutManager)child.GetLayoutManager(); // Checking Scroll position is necessary. Because, even if they have same width // values, their scroll positions can be different. if (!scrollingLeft && columnHeaderScrollPosition != child.GetScrolledX()) { // Column Header RecyclerView has the right scroll position. So, // considering it childLayoutManager.ScrollToPositionWithOffset(columnHeaderFirstItem, columnHeaderOffset); } Fit2(position, j, columnCacheWidth, column, childLayoutManager); } } } }
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; } } } }
public override void MeasureChildWithMargins(Android.Views.View child, int widthUsed, int heightUsed) { base.MeasureChildWithMargins(child, widthUsed, heightUsed); // If has fixed width is true, than calculation of the column width is not necessary. if (mTableView.HasFixedWidth()) { return; } int position = GetPosition(child); ColumnLayoutManager childLayoutManager = (ColumnLayoutManager)((CellRecyclerView)child).GetLayoutManager(); // the below codes should be worked when it is scrolling vertically if (mCellRecyclerView.ScrollState != RecyclerView.ScrollStateIdle) { if (childLayoutManager.IsNeedFit()) { // Scrolling up if (mLastDy < 0) { Log.Error(LogTag, position + " fitWidthSize all vertically up"); FitWidthSize(true); } else { // Scrolling down Log.Error(LogTag, position + " fitWidthSize all vertically down"); FitWidthSize(false); } // all columns have been fitted. childLayoutManager.ClearNeedFit(); } // Set the right initialPrefetch size to improve performance childLayoutManager.InitialPrefetchItemCount = childLayoutManager.ChildCount; } else { // That means,populating for the first time like fetching all data to display. // It shouldn't be worked when it is scrolling horizontally ."getLastDx() == 0" // control for it. if (childLayoutManager.GetLastDx() == 0 && mCellRecyclerView.ScrollState == RecyclerView.ScrollStateIdle) { if (childLayoutManager.IsNeedFit()) { mNeedFit = true; // all columns have been fitted. childLayoutManager.ClearNeedFit(); } if (mNeedFit) { // for the first time to populate adapter if (mRowHeaderLayoutManager.FindLastVisibleItemPosition() == position) { FitWidthSize2(false); Log.Error(LogTag, position + " fitWidthSize populating data for the first time"); mNeedFit = false; } } } } }
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); }