最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Xamarin Android C# empty space after adding divider using ItemDecoration - Stack Overflow

programmeradmin5浏览0评论

I am using a custom divider.

And I add a divider after each itemView.

divider

When I select several elements next to each other, it turns out that the divider is between them. And you can see white space on the left.

divider between items

 public OrderRecyclerViewItemDecoration(Context context, int orientation) : base(context, orientation)
    {
        Drawable = context.CompatGetDrawable(ResourceConstant.Drawable.recycler_view_divider);
    }

    public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
    {
        var childCount = parent.ChildCount;
        for (int i = 0; i < childCount; i++)
        {
            var child = parent.GetChildAt(i);
            var childPosition = parent.GetChildAdapterPosition(child);
            var viewType = parent.GetAdapter()!.GetItemViewType(childPosition);

            if (!NeedDivider(viewType))
                continue;
            
            var orderItemLeft = child.FindViewById<View>(Resource.Id.order_item_left);
            int left = orderItemLeft?.Right ?? child.Left;
            
            Drawable.Bounds = new(left, child.Bottom, child.Right, child.Bottom + Drawable.IntrinsicHeight);
            Drawable.Draw(c);
        }
    }

How can I make a divider inside each item?

发布评论

评论列表(0)

  1. 暂无评论