public static abstract class RecyclerView.ItemDecoration
extends Object
java.lang.Object | |
↳ | android.support.v7.widget.RecyclerView.ItemDecoration |
Known Direct Subclasses |
ItemDecoration允许应用程序从适配器的数据集中为特定的项目视图添加特殊的图形和布局偏移量。 这对于在项目之间绘制分隔线,突出显示,视觉分组边界等等非常有用。
所有商品装饰都是按照它们添加的顺序,在商品视图之前(在 onDraw()
之后以及在商品之后(在 onDrawOver(Canvas, RecyclerView, RecyclerView.State)
中) onDrawOver(Canvas, RecyclerView, RecyclerView.State)
。
Public constructors |
|
---|---|
RecyclerView.ItemDecoration() |
Public methods |
|
---|---|
void |
getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) |
void |
getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) 检索给定项目的任何偏移量。 |
void |
onDraw(Canvas c, RecyclerView parent) |
void |
onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) 在提供给RecyclerView的Canvas中绘制任何适当的装饰。 |
void |
onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) 在提供给RecyclerView的Canvas中绘制任何适当的装饰。 |
void |
onDrawOver(Canvas c, RecyclerView parent) 此方法已弃用。 覆盖 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
RecyclerView.ItemDecoration ()
void getItemOffsets (Rect outRect, int itemPosition, RecyclerView parent)
此方法已弃用。
使用getItemOffsets(Rect, View, RecyclerView, State)
Parameters | |
---|---|
outRect |
Rect
|
itemPosition |
int
|
parent |
RecyclerView
|
void getItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
检索给定项目的任何偏移量。 outRect
每个字段指定项目视图应插入的像素数量,类似于填充或边距。 默认实现将outRect的边界设置为0并返回。
如果此ItemDecoration不影响项目视图的位置,则应在返回之前将 outRect
(左侧,顶部,右侧,底部)的所有四个字段设置为零。
如果您需要访问适配器以获取其他数据,则可以致电 getChildAdapterPosition(View)
以获取视图的适配器位置。
Parameters | |
---|---|
outRect |
Rect : Rect to receive the output. |
view |
View : The child view to decorate |
parent |
RecyclerView : RecyclerView this ItemDecoration is decorating |
state |
RecyclerView.State : The current state of RecyclerView. |
void onDraw (Canvas c, RecyclerView parent)
此方法已弃用。
覆盖onDraw(Canvas, RecyclerView, RecyclerView.State)
Parameters | |
---|---|
c |
Canvas
|
parent |
RecyclerView
|
void onDraw (Canvas c, RecyclerView parent, RecyclerView.State state)
在提供给RecyclerView的Canvas中绘制任何适当的装饰。 任何由此方法绘制的内容都将在绘制项目视图之前绘制,并将出现在视图下方。
Parameters | |
---|---|
c |
Canvas : Canvas to draw into |
parent |
RecyclerView : RecyclerView this ItemDecoration is drawing into |
state |
RecyclerView.State : The current state of RecyclerView |
void onDrawOver (Canvas c, RecyclerView parent, RecyclerView.State state)
在提供给RecyclerView的Canvas中绘制任何适当的装饰。 任何由此方法绘制的内容都将在绘制项目视图后绘制,并因此出现在视图上。
Parameters | |
---|---|
c |
Canvas : Canvas to draw into |
parent |
RecyclerView : RecyclerView this ItemDecoration is drawing into |
state |
RecyclerView.State : The current state of RecyclerView. |
void onDrawOver (Canvas c, RecyclerView parent)
此方法已弃用。
覆盖onDrawOver(Canvas, RecyclerView, RecyclerView.State)
Parameters | |
---|---|
c |
Canvas
|
parent |
RecyclerView
|