parent
6ff17b6930
commit
add179c578
@ -1,40 +0,0 @@ |
|||||||
package com.android.base.widget.recyclerview; |
|
||||||
|
|
||||||
import android.graphics.Rect; |
|
||||||
import android.view.View; |
|
||||||
|
|
||||||
import androidx.annotation.NonNull; |
|
||||||
import androidx.recyclerview.widget.RecyclerView; |
|
||||||
|
|
||||||
|
|
||||||
public class MarginDecoration extends RecyclerView.ItemDecoration { |
|
||||||
|
|
||||||
private int mTop; |
|
||||||
private int mLeft; |
|
||||||
private int mRight; |
|
||||||
private int mBottom; |
|
||||||
|
|
||||||
public MarginDecoration(int left, int top, int right, int bottom) { |
|
||||||
mTop = top; |
|
||||||
mBottom = bottom; |
|
||||||
mRight = right; |
|
||||||
mLeft = left; |
|
||||||
} |
|
||||||
|
|
||||||
public MarginDecoration(int margin) { |
|
||||||
mTop = margin; |
|
||||||
mBottom = margin; |
|
||||||
mRight = margin; |
|
||||||
mLeft = margin; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { |
|
||||||
super.getItemOffsets(outRect, view, parent, state); |
|
||||||
outRect.top = mTop; |
|
||||||
outRect.bottom = mBottom; |
|
||||||
outRect.left = mLeft; |
|
||||||
outRect.right = mRight; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,33 @@ |
|||||||
|
package com.android.base.widget.recyclerview |
||||||
|
|
||||||
|
import android.graphics.Rect |
||||||
|
import android.view.View |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
import androidx.recyclerview.widget.RecyclerView.ItemDecoration |
||||||
|
import androidx.recyclerview.widget.RecyclerView.State |
||||||
|
|
||||||
|
class MarginDecoration : ItemDecoration { |
||||||
|
|
||||||
|
private var top: Int |
||||||
|
private var left: Int |
||||||
|
private var right: Int |
||||||
|
private var bottom: Int |
||||||
|
|
||||||
|
constructor(left: Int = 0, top: Int = 0, right: Int = 0, bottom: Int = 0) { |
||||||
|
this.top = top |
||||||
|
this.bottom = bottom |
||||||
|
this.right = right |
||||||
|
this.left = left |
||||||
|
} |
||||||
|
|
||||||
|
constructor(margin: Int) : this(margin, margin, margin, margin) |
||||||
|
|
||||||
|
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: State) { |
||||||
|
super.getItemOffsets(outRect, view, parent, state) |
||||||
|
outRect.top = top |
||||||
|
outRect.bottom = bottom |
||||||
|
outRect.left = left |
||||||
|
outRect.right = right |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue