Exemple #1
0
        public override void OnLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
        {
            base.OnLayoutChildren(recycler, state);

            if (Width > 0 && Height > 0 && (Width != _lastWidth || Height != _lastHeight))
            {
                _lastWidth  = Width;
                _lastHeight = Height;

                CalculateSpanCount();
            }
        }
        public override void OnDraw(Android.Graphics.Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            base.OnDraw(c, parent, state);

            if (this.GetOrientation(parent) == LinearLayoutManager.Vertical)
            {
                this.DrawVertical(c, parent);
            }
            else
            {
                this.DrawHorizontal(c, parent);
            }
        }
Exemple #3
0
            public override void OnDraw(Canvas cValue, RecyclerView parent, RecyclerView.State state)
            {
                base.OnDraw(cValue, parent, state);

                _layout.Layout(parent.Left, 0, parent.Right, _layout.MeasuredHeight);

                for (int i = 0; i < parent.ChildCount; i++)
                {
                    var view = parent.GetChildAt(i);

                    if (parent.GetChildAdapterPosition(view) == parent.ChildCount - 1)
                    {
                    }
                }
            }
Exemple #4
0
        public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            int left  = parent.PaddingLeft;
            int right = parent.Width - parent.PaddingRight;

            int childCount = parent.ChildCount;

            for (int i = 0; i < childCount; i++)
            {
                View child = parent.GetChildAt(i);
                RecyclerView.LayoutParams parametres = (RecyclerView.LayoutParams)child.LayoutParameters;
                int top    = child.Bottom + parametres.BottomMargin;
                int bottom = top + divider.IntrinsicHeight;
                divider.SetBounds(left, top, right, bottom);
                divider.Draw(c);
            }
        }
        public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            var childCount = parent.ChildCount;

            if (childCount == 0)
            {
                return;
            }

            for (int i = 0; i + 1 < childCount; i++)
            {
                var child      = parent.GetChildAt(i);
                var viewHolder = parent.GetChildViewHolder(child);

                Type     type       = viewHolder.GetType();
                object[] attributes = type.GetCustomAttributes(typeof(ShadowAttribute), false);

                if (attributes.Length != 1)
                {
                    continue;
                }

                ShadowAttribute shadowAttr = attributes [0] as ShadowAttribute;

                if (ShouldDraw(child) && shadowAttr != null)
                {
                    var m     = shadowAttr.Modes;
                    var left  = parent.PaddingLeft;
                    var right = child.Right + child.PaddingRight;

                    if (m.HasFlag(top) && topShadowHeightInPixels > 0 && parent.GetChildAdapterPosition(child) != 0)
                    {
                        var shadowBottom = child.Top + topShadowHeightInPixels;
                        shadow.SetBounds(left, child.Top, right, shadowBottom);
                        shadow.Draw(c);
                    }

                    if (m.HasFlag(bottom) && bottomShadowHeightInPixels > 0)
                    {
                        var reverseShadowTop = child.Bottom - bottomShadowHeightInPixels;
                        reverseShadow.SetBounds(left, reverseShadowTop, right, child.Bottom);
                        reverseShadow.Draw(c);
                    }
                }
            }
        }
        public override void OnDrawOver(Canvas cValue, RecyclerView parent, RecyclerView.State state)
        {
            int left       = parent.PaddingLeft;
            int right      = parent.Width - parent.PaddingRight;
            int childCount = parent.ChildCount;

            for (int i = 1; i < childCount; i++)
            {
                View child = parent.GetChildAt(i);
                RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams)child.LayoutParameters;
                int size   = _dividerHeight;
                int top    = child.Top - lp.TopMargin - _dividerHeight;
                int bottom = top + size;
                _divider.Bounds = new Rect(left, top, right, bottom);
                _divider.Draw(cValue);
            }
        }
        public override void OnMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec)
        {
            int  width          = Width;
            bool isWidthChanged = oldWidth != width;

            if (isWidthChanged && ColumnWidth > 0 && width > 0)
            {
                oldWidth = width;
                int totalWidth     = width - PaddingRight - PaddingLeft;
                int totalWidthInDp = Utils.PxToDp(totalWidth, Context.Resources);
                if (!widthToColumnCount.ContainsKey(totalWidthInDp))
                {
                    widthToColumnCount[totalWidthInDp] = Utils.CalculateColumnCount(ColumnWidth, totalWidthInDp);
                }
                SpanCount = widthToColumnCount[totalWidthInDp];
            }
            base.OnMeasure(recycler, state, widthSpec, heightSpec);
        }
Exemple #8
0
        public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            base.OnDraw(c, parent, state);
            int left  = parent.PaddingLeft;
            int right = parent.Width - parent.PaddingRight;

            for (int i = 0; i < parent.ChildCount; i++)
            {
                View child = parent.GetChildAt(i);

                ViewGroup.MarginLayoutParams parameters = (ViewGroup.MarginLayoutParams)child.LayoutParameters;

                int top    = child.Bottom + parameters.BottomMargin;
                int bottom = top + drawable.IntrinsicHeight;

                drawable.SetBounds(left, top, right, bottom);
                drawable.Draw(c);
            }
        }
Exemple #9
0
        public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            int left  = parent.Left;
            int right = parent.Right;

            int childCount = parent.ChildCount;
            CustomViewHolder?prevHolder = null;

            for (var i = 0; i < childCount; i++)
            {
                View?child = parent.GetChildAt(i);

                if (child is null)
                {
                    continue;
                }
                if (!(parent.GetChildViewHolder(child) is CustomViewHolder holder))
                {
                    continue;
                }
                if (holder.RowInfo is null)
                {
                    continue;
                }
                if ((prevHolder is IHeaderViewHolder && !_SettingsView.ShowSectionTopBottomBorder) ||
                    (holder is IFooterViewHolder && !_SettingsView.ShowSectionTopBottomBorder) ||
                    (holder is IFooterViewHolder && !holder.RowInfo.Section.Any()) ||
                    (holder is IHeaderViewHolder || !holder.RowInfo.Section.IsVisible))
                {
                    prevHolder = holder;
                    continue;
                }

                int bottom = child.Top;
                int top    = bottom - _Drawable.IntrinsicHeight;
                _Drawable.SetBounds(left, top, right, bottom);
                _Drawable.Draw(c);

                prevHolder = holder;
            }
        }
Exemple #10
0
        /**
         * 处理测量逻辑
         *
         * @param recycler          RecyclerView
         * @param state             状态
         * @param widthMeasureSpec  宽度属性
         * @param heightMeasureSpec 高估属性
         */
        //@Override
        public override void OnMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(recycler, state, widthMeasureSpec, heightMeasureSpec);
            int             widthsize = View.MeasureSpec.GetSize(widthMeasureSpec);   //取出宽度的确切数值
            MeasureSpecMode widthmode = View.MeasureSpec.GetMode(widthMeasureSpec);   //取出宽度的测量模式

            int             heightsize = View.MeasureSpec.GetSize(heightMeasureSpec); //取出高度的确切数值
            MeasureSpecMode heightmode = View.MeasureSpec.GetMode(heightMeasureSpec); //取出高度的测量模式

            // 将 wrap_content 转换为 match_parent
            if (widthmode != MeasureSpecMode.Exactly && widthsize > 0)
            {
                widthmode = MeasureSpecMode.Exactly;
            }
            if (heightmode != MeasureSpecMode.Exactly && heightsize > 0)
            {
                heightmode = MeasureSpecMode.Exactly;
            }
            SetMeasuredDimension(View.MeasureSpec.MakeMeasureSpec(widthsize, widthmode),
                                 View.MeasureSpec.MakeMeasureSpec(heightsize, heightmode));
        }
Exemple #11
0
        public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            base.OnDraw(c, parent, state);
            int dividerLeft  = 32;
            int dividerRight = parent.Width - 32;

            for (int i = 0; i < parent.ChildCount; i++)
            {
                if (i != parent.ChildCount - 1)
                {
                    View child = parent.GetChildAt(i);
                    RecyclerView.LayoutParams @params = (RecyclerView.LayoutParams)child.LayoutParameters;

                    int dividerTop    = child.Bottom + @params.BottomMargin;
                    int dividerBottom = dividerTop + mDivider.IntrinsicHeight;

                    mDivider.SetBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
                    mDivider.Draw(c);
                }
            }
        }
            public override void OnDrawOver(Canvas cValue, RecyclerView parent, RecyclerView.State state)
            {
                var left  = parent.PaddingLeft;
                var right = parent.Width - parent.PaddingRight;

                var childCount = parent.ChildCount;

                for (var i = 0; i < childCount; i++)
                {
                    var child = parent.GetChildAt(i);

                    var layoutParams = (RecyclerView.LayoutParams)child.LayoutParameters;

                    var top    = child.Bottom + layoutParams.BottomMargin + (int)child.TranslationY;
                    var bottom = top + 2;

                    _divider.Alpha = (int)(child.Alpha * 255);
                    _divider.SetBounds(left, top, right, bottom);
                    _divider.Draw(cValue);
                }
            }
Exemple #13
0
        public void GetEdgeStates(Rect outRect, View child, SectionData sd, RecyclerView.State state)
        {
            LayoutManager.LayoutParams lp = (LayoutManager.LayoutParams)child.LayoutParameters;
            int position = lp.ViewPosition;

            int  column    = (position - sd.FirstContentPosition) % mNumColumns;
            bool isLtr     = mLayoutManager.LayoutDirection == ViewCompat.LayoutDirectionLtr;
            int  ltrColumn = AdjustColumnForLayoutDirection(column, isLtr);

            outRect.Left  = ltrColumn == 0 ? ItemDecorator.EXTERNAL : ItemDecorator.INTERNAL;
            outRect.Right = ltrColumn == mNumColumns - 1 ? ItemDecorator.EXTERNAL : ItemDecorator.INTERNAL;

            outRect.Top = position - column == sd.FirstContentPosition ? ItemDecorator.EXTERNAL : ItemDecorator.INTERNAL;
            // Reset position to left column and add num columns, if < itemcount then not last row.
            if (sd.LastContentItemFound)
            {
                outRect.Bottom = position + (mNumColumns - column) > sd.lastContentPosition ? ItemDecorator.EXTERNAL : ItemDecorator.INTERNAL;
            }
            else
            {
                outRect.Bottom = ItemDecorator.INTERNAL;
            }
        }
        public override void OnDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            int left  = parent.PaddingLeft;
            int right = parent.Width - parent.PaddingRight;

            int childCount = parent.GetAdapter().ItemCount;

            for (int i = 0; i < childCount; i++)
            {
                var child = parent.GetChildAt(i);

                if (child == null)
                {
                    return;
                }

                var lp = (RecyclerView.LayoutParams)child.LayoutParameters;

                int top = (int)(child.Top + lp.TopMargin + lp.BottomMargin + child.TranslationY);

                c.DrawLine(left + ((i + 1 < childCount) ? _sideSpace : 0), top, right, top, _paint);
            }
        }
        public override void OnDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state)
        {
            base.OnDrawOver(canvas, parent, state);
            var topChild = parent.GetChildAt(0);

            if (topChild == null)
            {
                return;
            }

            int topChildPosition = parent.GetChildAdapterPosition(topChild);

            if (topChildPosition == RecyclerView.NoPosition)
            {
                return;
            }

            View currentHeader = GetHeaderViewForItem(topChildPosition, parent);

            if (currentHeader == null)
            {
                return;
            }

            FixLayoutSize(parent, currentHeader);

            int  contactPoint   = currentHeader.Bottom;
            View childInContact = GetChildInContact(parent, contactPoint, topChildPosition);

            if (childInContact != null && IStickyHeaderRecyclerView.IsHeader(parent.GetChildAdapterPosition(childInContact)))
            {
                MoveHeader(canvas, currentHeader, childInContact);
                return;
            }

            DrawHeader(canvas, currentHeader);
        }
Exemple #16
0
        public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            var offset = (int)(_bottomOffset / 2);

            // iterate over every visible view
            for (int i = 0; i < parent.ChildCount; i++)
            {
                var view       = parent.GetChildAt(i);
                var parameters = (RecyclerView.LayoutParams)view.LayoutParameters;

                var position = parameters.ViewAdapterPosition;

                // finally draw the separator
                if (position < state.ItemCount)
                {
                    c.DrawLine(
                        view.Left + _leftOffset,
                        view.Bottom + offset,
                        view.Right,
                        view.Bottom + offset,
                        _paint);
                }
            }
        }
        public override void OnDrawOver(Canvas cValue, RecyclerView parent, RecyclerView.State state)
        {
            var left  = parent.PaddingLeft;
            var right = parent.Width - parent.PaddingRight;

            for (var i = 0; i < parent.ChildCount; i++)
            {
                var child = parent.GetChildAt(i);

                var parameters = child.LayoutParameters.JavaCast <RecyclerView.LayoutParams>();

                var top    = child.Bottom + parameters.BottomMargin;
                var bottom = top + _divider.IntrinsicHeight;

                _divider.SetBounds(left, top, right, bottom);

                if ((parent.GetChildAdapterPosition(child) == parent.GetAdapter().ItemCount - 1) && parent.Bottom < bottom)
                { // this prevent a parent to hide the last item's divider
                    parent.SetPadding(parent.PaddingLeft, parent.PaddingTop, parent.PaddingRight, bottom - parent.Bottom);
                }

                _divider.Draw(cValue);
            }
        }
        protected override Line CreateLine(GeneratorDirection direction,
                                           int extentOffset,
                                           int breadthOffset,
                                           int availableBreadth,
                                           RecyclerView.Recycler recycler,
                                           RecyclerView.State state,
                                           Uno.UI.IndexPath nextVisibleItem,
                                           bool isNewGroup
                                           )
        {
            if (ShouldInsertReorderingView(direction, extentOffset))
            {
                nextVisibleItem = GetAndUpdateReorderingIndex().Value;
            }

            var item = GetFlatItemIndex(nextVisibleItem);
            var view = recycler.GetViewForPosition(item, state);

            if (!(view is SelectorItem))
            {
                throw new InvalidOperationException($"Expected {nameof(SelectorItem)} but received {view?.GetType().ToString() ?? "<null>"}");
            }
            var size         = AddViewAtOffset(view, direction, extentOffset, breadthOffset, availableBreadth);
            var physicalSize = size.LogicalToPhysicalPixels();

            var breadth = (int)(ScrollOrientation == Orientation.Vertical ? physicalSize.Width : physicalSize.Height);

            return(new Line
            {
                NumberOfViews = 1,
                Extent = (int)(ScrollOrientation == Orientation.Vertical ? physicalSize.Height : physicalSize.Width),
                FirstItem = nextVisibleItem,
                LastItem = nextVisibleItem,
                Breadth = breadth
            });
        }