记录RecyclerView添加分割线时判断第一个item的方法

recyclerview.addItemDecoration(new RecyclerView.ItemDecoration() {

@Override

    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

super.getItemOffsets(outRect, view, parent, state);

int childPosition=parent.getChildAdapterPosition(view);

int last=parent.getAdapter().getItemCount()-1;

if (childPosition==last){

outRect.bottom=0;

}else {

outRect.bottom=5;

}

}

});

老是忘记做个记录!

你可能感兴趣的:(记录RecyclerView添加分割线时判断第一个item的方法)