|
|
@@ -0,0 +1,54 @@
|
|
|
+package com.itant.shibei.widget;
|
|
|
+
|
|
|
+import android.graphics.Rect;
|
|
|
+import android.view.View;
|
|
|
+
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 均等分割线
|
|
|
+ */
|
|
|
+public class NormalDividerItemDecoration extends RecyclerView.ItemDecoration {
|
|
|
+ private int halfSpace;
|
|
|
+
|
|
|
+ public NormalDividerItemDecoration(int space) {
|
|
|
+ this.halfSpace = space / 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
|
|
+ super.getItemOffsets(outRect, view, parent, state);
|
|
|
+ /*if (parent.getPaddingLeft() != halfSpace) {
|
|
|
+ parent.setPadding(halfSpace, halfSpace, halfSpace, halfSpace);
|
|
|
+ parent.setClipToPadding(false);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /*outRect.left = halfSpace;
|
|
|
+ outRect.right = halfSpace;
|
|
|
+ outRect.top = halfSpace;
|
|
|
+ if (parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1) {
|
|
|
+ outRect.bottom = halfSpace;
|
|
|
+ } else {
|
|
|
+ outRect.bottom = 0;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /*parent.setClipToPadding(false);
|
|
|
+ if (parent.getChildAdapterPosition(view) != parent.getAdapter().getItemCount() - 1) {
|
|
|
+ parent.setPadding(halfSpace, halfSpace, halfSpace, 0);
|
|
|
+ } else {
|
|
|
+ parent.setPadding(halfSpace, halfSpace, halfSpace, halfSpace);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ // Rect outRect表示 item 的上下左右所留下的边距。其中 outRect 的 left,top,right,bottom 即为 item 四周留下的边距的距离,默认都为 0 ;
|
|
|
+ // 让分割线一致
|
|
|
+ parent.setClipToPadding(false);
|
|
|
+ outRect.left = halfSpace;
|
|
|
+ outRect.top = halfSpace;
|
|
|
+ outRect.right = halfSpace;
|
|
|
+ if (parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1) {
|
|
|
+ outRect.bottom = halfSpace;
|
|
|
+ } else {
|
|
|
+ outRect.bottom = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|