Exemplo n.º 1
0
        internal virtual void LayoutChunk(FlexibleViewRecycler recycler,
                                          LayoutState layoutState, LayoutChunkResult result)
        {
            FlexibleViewViewHolder holder = layoutState.Next(recycler);

            if (holder == null)
            {
                // if we are laying out views in scrap, this may return null which means there is
                // no more items to layout.
                result.Finished = true;
                return;
            }

            if (mShouldReverseLayout == (layoutState.LayoutDirection == LayoutState.LAYOUT_START))
            {
                AddView(holder);
            }
            else
            {
                AddView(holder, 0);
            }

            result.Consumed = orientationHelper.GetViewHolderMeasurement(holder);

            float left, top, width, height;

            if (Orientation == VERTICAL)
            {
                width  = Width - PaddingLeft - PaddingRight;
                height = result.Consumed;
                left   = PaddingLeft;
                if (layoutState.LayoutDirection == LayoutState.LAYOUT_END)
                {
                    top = layoutState.Offset;
                }
                else
                {
                    top = layoutState.Offset - height;
                }
                LayoutChild(holder, left, top, width, height);
            }
            else
            {
                width  = result.Consumed;
                height = Height - PaddingTop - PaddingBottom;
                top    = PaddingTop;
                if (layoutState.LayoutDirection == LayoutState.LAYOUT_END)
                {
                    left = layoutState.Offset;
                }
                else
                {
                    left = layoutState.Offset - width;
                }
                LayoutChild(holder, left, top, width, height);
            }

            result.Focusable = true;
        }
Exemplo n.º 2
0
        internal override void LayoutChunk(FlexibleView.Recycler recycler,
                                           LayoutState layoutState, LayoutChunkResult result)
        {
            bool layingOutInPrimaryDirection =
                layoutState.ItemDirection == LayoutState.ITEM_DIRECTION_TAIL;

            int count = mSpanCount;

            for (int i = 0; i < count; i++)
            {
                FlexibleView.ViewHolder holder = layoutState.Next(recycler);
                if (holder == null)
                {
                    result.Finished = true;
                    return;
                }

                if (layingOutInPrimaryDirection)
                {
                    AddView(holder);
                }
                else
                {
                    AddView(holder, 0);
                }

                result.Consumed = mOrientationHelper.GetViewHolderMeasurement(holder);

                float left, top, width, height;
                if (mOrientation == VERTICAL)
                {
                    width  = (Width - PaddingLeft - PaddingRight) / count;
                    height = result.Consumed;
                    if (layoutState.LayoutDirection == LayoutState.LAYOUT_END)
                    {
                        left = PaddingLeft + width * i;
                        top  = layoutState.Offset;
                    }
                    else
                    {
                        left = PaddingLeft + width * (count - 1 - i);
                        top  = layoutState.Offset - height;
                    }
                    LayoutChild(holder, left, top, width, height);
                }
                else
                {
                    width  = result.Consumed;
                    height = (Height - PaddingTop - PaddingBottom) / count;
                    if (layoutState.LayoutDirection == LayoutState.LAYOUT_END)
                    {
                        top  = PaddingTop + height * i;
                        left = layoutState.Offset;
                    }
                    else
                    {
                        top  = PaddingTop + height * (count - 1 - i);
                        left = layoutState.Offset - width;
                    }
                    LayoutChild(holder, left, top, width, height);
                }
            }
        }