【问题标题】:The ItemDecoration is displayed over the RecyclerView, not below itItemDecoration 显示在 RecyclerView 上方,而不是下方
【发布时间】:2019-10-12 03:29:49
【问题描述】:

我正在创建一个带有硬编码内容的RecyclerView,并且元素显示正确,但是我想放置一个Item装饰,但是它显示在RecyclerView上,我希望它显示在下面。

我尝试通过扩展自定义 LinePagerIndicatorDecoration 类并更改指示器的高度来创建它,但它不起作用。

recyclerNew?.apply {
                layoutManager = LinearLayoutManager(_context, RecyclerView.HORIZONTAL, false)
                addItemDecoration(LinePagerIndicatorDecoration(_context))
                adapter = newsAdapter
                setHasFixedSize(true)
                invalidate()
            }

ItemDecoration 显示在回收器上方,我想要它在下方。

有人可以帮助我吗?

【问题讨论】:

  • 首先检查默认ItemDecoration。如果没问题,那么这是您的自定义ItemDecoration 的问题
  • 尝试重写 RecyclerView.ItemDecoration.onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) 方法来绘制你的指标,而不是 RecyclerView.ItemDecoration.onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state )

标签: android kotlin android-recyclerview item-decoration


【解决方案1】:

你可以像这样使用 ItemDecoration:

// To give the border line in the recyclerview
RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration( getApplicationContext(), DividerItemDecoration.VERTICAL ); 
recyclerView.addItemDecoration( itemDecoration );

【讨论】:

    猜你喜欢
    • 2017-12-08
    • 1970-01-01
    • 2021-09-15
    • 2016-05-23
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多