package com.bwf.tuanche.car_select.view;import android.content.context;
import android.content.res.typedarray;
import android.graphics.canvas;
import android.graphics.paint;
import android.graphics.rect;
import android.graphics.drawable.drawable;
import android.support.v4.content.contextcompat;
import android.support.v7.widget.linearlayoutmanager;
import android.support.v7.widget.recyclerview;
import android.view.view;
/*** created by wanli on 2016/8/19.
* description:
*/public class recycleviewdivider extends recyclerview.itemdecoration ;
/*** 預設分割線:高度為2px,顏色為灰色**
@param
context
*@param
orientation
列表方向
*/public recycleviewdivider(context context, int orientation)
morientation = orientation;
final typedarray a = context.obtainstyledattributes(attrs
);mdivider = a.getdrawable(0);
a.recycle();
}/**
* 自定義分割線**
@param
context
*@param
orientation
列表方向
*@param
drawableid
分割線*/
public recycleviewdivider(context context, int orientation, int drawableid)
/*** 自定義分割線**
@param
context
*@param
orientation
列表方向
*@param
dividerheight
分割線高度
*@param
dividercolor
分割線顏色
*/public recycleviewdivider(context context, int orientation, int dividerheight, int dividercolor)
//獲取分割線尺寸
@override
public void
getitemoffsets(rect outrect, view view, recyclerview parent, recyclerview.state state)
//繪製分割線
@override
public void
ondraw(canvas c, recyclerview parent, recyclerview.state state) else
}//繪製橫向 item 分割線
private void
drawhorizontal(canvas canvas, recyclerview parent)
if (mpaint != null) }}
//繪製縱向 item 分割線
private void
drawvertical(canvas canvas, recyclerview parent)
if (mpaint != null) }}
}
使用方法
recyclerview.additemdecoration(new recycleviewdivider(this.getcontext(), linearlayoutmanager.vertical));recyclerview.additemdecoration(new recycleviewdivider(this.getcontext(), linearlayoutmanager.horizontal
));
RecycleView區域性重新整理
向指定位置插入item public final void notifyiteminserted int position 移除指定位置item public final void notifyitemremoved int position 更新指定位置item public final void...
Recycleview分頁載入
ui上無載入動畫 原理 當最後乙個item顯示時,執行載入操作 同理也可設定成最後某個item顯示時,提前執行載入操作 1 重寫recycleview滑動監聽 public abstract class loadmoreonscrolllistener extends recyclerview.on...
RecycleView 線條滾動
滑動主要 mrecyclerview.addonscrolllistener new recyclerview.onscrolllistener override public void onscrolled recyclerview recyclerview,int dx,int dy 計算水平滾...