本文介绍了RecyclerView ItemDecoration的onDraw的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的 RecyclerView.ItemDecoration 说,的onDraw(帆布C,RecyclerView父)是pcated德$ P $。相反,他们说要重写的onDraw(帆布,RecyclerView,RecyclerView.State)

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

不过,我不明白我应该通过这个方法什么样的状态的对象。我看到在国家RecyclerView的方法,通过内部像: onLayoutChildren scrollVerticallyBy onFocusSearchFailed 。但我看不出例子来使用State对象编程方式传递给的onDraw 方式。没有任何人有任何的投入呢?

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?

推荐答案

的OnDraw()将被称为 RecyclerView 适当国家规定,你不必自己调用它。此外,它建议重写 onDrawOver() RecyclerView.ItemDecoration 代替。

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.

这是吸引RecyclerView项目之间的分隔线装饰的一个例子:

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

这篇关于RecyclerView ItemDecoration的onDraw的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 14:43
查看更多