|
|
@@ -6,13 +6,13 @@ import android.view.View;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
/**
|
|
|
- * 均等分割线
|
|
|
+ * 均等分割线,对于CardView,默认有8dp的margin_bottom,可根据需要进行加减
|
|
|
*/
|
|
|
public class NormalDividerItemDecoration extends RecyclerView.ItemDecoration {
|
|
|
- private int halfSpace;
|
|
|
+ private int mSpace;
|
|
|
|
|
|
public NormalDividerItemDecoration(int space) {
|
|
|
- this.halfSpace = space / 2;
|
|
|
+ this.mSpace = space;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -42,11 +42,11 @@ public class NormalDividerItemDecoration extends RecyclerView.ItemDecoration {
|
|
|
// Rect outRect表示 item 的上下左右所留下的边距。其中 outRect 的 left,top,right,bottom 即为 item 四周留下的边距的距离,默认都为 0 ;
|
|
|
// 让分割线一致
|
|
|
parent.setClipToPadding(false);
|
|
|
- outRect.left = halfSpace;
|
|
|
- outRect.top = halfSpace;
|
|
|
- outRect.right = halfSpace;
|
|
|
+ outRect.left = mSpace;
|
|
|
+ outRect.top = mSpace;
|
|
|
+ outRect.right = mSpace;
|
|
|
if (parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1) {
|
|
|
- outRect.bottom = halfSpace;
|
|
|
+ outRect.bottom = mSpace;
|
|
|
} else {
|
|
|
outRect.bottom = 0;
|
|
|
}
|