RecyclerView ItemDecoration onDraw

跟風遠走 提交于 2019-12-13 21:05:57

问题


The spec for RecyclerView.ItemDecoration says that onDraw(Canvas c, RecyclerView parent) is deprecated. Instead, they say to override onDraw(Canvas, RecyclerView, RecyclerView.State).

However, I don't understand what kind of State object I should pass to this method. I see State passed internally in RecyclerView's methods like: onLayoutChildren, scrollVerticallyBy, and onFocusSearchFailed. But I see no examples to use the State object programmatically to pass to onDraw method. Does anybody have any input into this?


回答1:


OnDraw() will be called by RecyclerView with proper state set, you need not call it yourself. Also, its recommended to override onDrawOver() of RecyclerView.ItemDecoration instead.

An example of a decoration that draws divider lines between RecyclerView items: https://gist.github.com/alexfu/0f464fc3742f134ccd1e



来源:https://stackoverflow.com/questions/27608195/recyclerview-itemdecoration-ondraw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!