RecyclerView去除底部分割线

问题:

RecyclerView去除底部分割线

解决方式:

参照DividerItemDecoration重写一个类,重写方法:

public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        if (this.mDivider == null) {
            outRect.set(0, 0, 0, 0);
        } else {
            if (this.mOrientation == 1) {
                int lastPosition = state.getItemCount() - 1;
                int position = parent.getChildAdapterPosition(view);
                if (position < lastPosition) {
                    outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
                } else {
                    outRect.set(0, 0, 0, 0);
                }
            } else {
                int lastPosition = state.getItemCount() - 1;
                int position = parent.getChildAdapterPosition(view);
                if (position < lastPosition) {
                    outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
                } else {
                    outRect.set(0, 0, 0, 0);
                }
            }
        }
    }

thanks 原文:RecyclerView ItemDecoration底部分割线

你可能感兴趣的:(RecyclerView去除底部分割线)