github:https://github.com/lvzhihao100/PinHeadForRecyclerView
简书:https://www.jianshu.com/p/590b26046195
特点
- 使用ItemDecoration实现
- 两种悬浮方式
- 悬浮头部可以自定义,自己画
- 内置常见悬浮头部
展示
| 悬浮头不可推动 |
| 悬浮头可推动 |
| 仿魅族手机电话本悬浮头可推动 |
依赖
compile 'com.github.lvzhihao100:PinHeadForRecyclerView:1.3'
使用方式
PInHeadItemDecoration floatingItemDecoration = new PInHeadItemDecoration();
recyclerView.addItemDecoration(floatingItemDecoration);
floatingItemDecoration
.bgColor(context.getResources().getColor(R.color.hint_bg))//设置头部背景颜色
.textSize(30 * WindowUtil.csw / WindowUtil.width)//设置画笔字体大小
.titleHeight(40 * WindowUtil.csw / WindowUtil.width);//设置悬浮头部的高度
自定义悬浮头部,实现DecorationDrawer接口,
floatingItemDecoration.setDecorationDrawer(new DecorationDrawer() {
//绘制滑动的头部
@Override
public void drawVertical(Canvas canvas, String s, float v, float v1, float v2, float v3, Paint paint, Paint paint1, float v4, int i) {
}
//绘制悬浮在最上面的头部
@Override
public void drawFlow(Canvas canvas, String s, float v, float v1, float v2, float v3, Paint paint, Paint paint1, float v4, int i) {
}
});
设置魅族样式悬浮头
floatingItemDecoration.setDecorationDrawer(new MeizuDecorationDrawer());