Esempio n. 1
0
        /// <summary>
        /// Fill a row.
        /// </summary>
        /// <param name="markerLine">      Line indicating the top edge of the row. </param>
        /// <param name="anchorPosition">  Position of the first view in the row. </param>
        /// <param name="direction">       Direction of edge to fill towards. </param>
        /// <param name="measureRowItems"> Measure the row items. </param>
        /// <param name="sd">              Section data. </param>
        /// <param name="state">           Layout state. </param>
        /// <returns> The height of the new row. </returns>
        public int fillRow(int markerLine, int anchorPosition, LayoutManager.Direction direction, bool measureRowItems, SectionData sd, LayoutState state)
        {
            int rowHeight = 0;

            LayoutState.View[] views = new LayoutState.View[mNumColumns];
            for (int i = 0; i < mNumColumns; i++)
            {
                int position = anchorPosition + i;
                if (position >= state.recyclerState.ItemCount)
                {
                    break;
                }

                LayoutState.View view = state.GetView(position);
                if (view.LayoutParams.FirstPosition != sd.firstPosition)
                {
                    state.CacheView(position, view.view);
                    break;
                }

                if (measureRowItems)
                {
                    MeasureChild(view, sd);
                }
                else
                {
                    state.DecacheView(i + anchorPosition);
                }
                rowHeight = Math.Max(rowHeight, mLayoutManager.GetDecoratedMeasuredHeight(view.view));
                views[i]  = view;
            }

            bool directionIsStart = direction == LayoutManager.Direction.START;

            if (directionIsStart)
            {
                markerLine -= rowHeight;
            }

            for (int i = 0; i < mNumColumns; i++)
            {
                int col = directionIsStart ? mNumColumns - i - 1 : i;
                if (views[col] == null)
                {
                    continue;
                }
                LayoutChild(views[col], markerLine, col, rowHeight, sd, state);
                AddView(views[col], col + anchorPosition, direction, state);
            }

            return(rowHeight);
        }
Esempio n. 2
0
        protected int AddView(LayoutState.View child, int position, LayoutManager.Direction direction, LayoutState state)
        {
            int addIndex;

            if (direction == LayoutManager.Direction.START)
            {
                addIndex = 0;
            }
            else
            {
                addIndex = mLayoutManager.ChildCount;
            }

            state.DecacheView(position);
            mLayoutManager.AddView(child.view, addIndex);

            return(addIndex);
        }
Esempio n. 3
0
        public override int FillToStart(int leadingEdge, int markerLine, int anchorPosition, SectionData sd, LayoutState state)
        {
            // Check to see if we have to adjust for minimum section height. We don't if there is an
            // attached non-header view in this section.
            bool applyMinHeight = false;

            for (int i = 0; i < state.recyclerState.ItemCount; i++)
            {
                View check = mLayoutManager.GetChildAt(0);
                if (check == null)
                {
                    applyMinHeight = false;
                    break;
                }

                LayoutManager.LayoutParams checkParams = (LayoutManager.LayoutParams)check.LayoutParameters;
                if (checkParams.FirstPosition != sd.firstPosition)
                {
                    applyMinHeight = true;
                    break;
                }

                if (!checkParams.isHeader)
                {
                    applyMinHeight = false;
                    break;
                }
            }

            // Work out offset to marker line by measuring items from the end. If section height is less
            // than min height, then adjust marker line and then lay out items.
            int measuredPositionsMarker = -1;
            int sectionHeight           = 0;
            int minHeightOffset         = 0;

            if (applyMinHeight)
            {
                for (int i = anchorPosition; i >= 0; i--)
                {
                    LayoutState.View measure = state.GetView(i);
                    state.CacheView(i, measure.view);
                    LayoutManager.LayoutParams lp = measure.LayoutParams;
                    if (lp.FirstPosition != sd.firstPosition)
                    {
                        break;
                    }

                    if (lp.isHeader)
                    {
                        continue;
                    }

                    measureChild(measure, sd);
                    sectionHeight          += mLayoutManager.GetDecoratedMeasuredHeight(measure.view);
                    measuredPositionsMarker = i;
                    if (sectionHeight >= sd.minimumHeight)
                    {
                        break;
                    }
                }

                if (sectionHeight < sd.minimumHeight)
                {
                    minHeightOffset = sectionHeight - sd.minimumHeight;
                    markerLine     += minHeightOffset;
                }
            }

            for (int i = anchorPosition; i >= 0; i--)
            {
                if (markerLine - minHeightOffset < leadingEdge)
                {
                    break;
                }

                LayoutState.View           next = state.GetView(i);
                LayoutManager.LayoutParams lp   = next.LayoutParams;
                if (lp.isHeader)
                {
                    state.CacheView(i, next.view);
                    break;
                }
                if (lp.FirstPosition != sd.firstPosition)
                {
                    state.CacheView(i, next.view);
                    break;
                }

                if (!applyMinHeight || i < measuredPositionsMarker)
                {
                    measureChild(next, sd);
                }
                else
                {
                    state.DecacheView(i);
                }
                markerLine = layoutChild(next, markerLine, LayoutManager.Direction.START, sd, state);
                AddView(next, i, LayoutManager.Direction.START, state);
            }

            return(markerLine);
        }