问题
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