package com.android.app_base.widget;
|
|
import android.graphics.Rect;
|
import android.view.View;
|
|
import androidx.annotation.NonNull;
|
import androidx.recyclerview.widget.RecyclerView;
|
|
/**
|
* @author Ljj
|
* @date 2023.03.18. 20:46
|
* @desc
|
*/public class LinearItemDecoration extends RecyclerView.ItemDecoration {
|
private int leftSpace;
|
private int rightSpace;
|
private int topSpace;
|
private int bottomSpace;
|
|
private int firstTop = -1;
|
|
public LinearItemDecoration(){
|
|
}
|
|
public LinearItemDecoration(int space) {
|
leftSpace = rightSpace = topSpace = bottomSpace = space;
|
}
|
|
public LinearItemDecoration(int horizontalSpace,int verticalSpace) {
|
rightSpace = leftSpace = horizontalSpace;
|
topSpace = bottomSpace = verticalSpace;
|
}
|
|
public LinearItemDecoration(int leftSpace, int rightSpace, int topSpace, int bottomSpace) {
|
this.leftSpace = leftSpace;
|
this.rightSpace = rightSpace;
|
this.topSpace = topSpace;
|
this.bottomSpace = bottomSpace;
|
}
|
|
@Override
|
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
super.getItemOffsets(outRect, view, parent, state);
|
outRect.left = leftSpace;
|
outRect.right = rightSpace;
|
outRect.bottom = bottomSpace;
|
outRect.top = topSpace;
|
if ( firstTop != -1 && firstTop >= 0){
|
if (parent.getChildLayoutPosition(view) == 0)
|
outRect.top = firstTop;
|
}
|
}
|
|
public void setTopSpace(int topSpace) {
|
this.topSpace = topSpace;
|
}
|
|
public void setLeftSpace(int leftSpace) {
|
this.leftSpace = leftSpace;
|
}
|
|
public void setRightSpace(int rightSpace) {
|
this.rightSpace = rightSpace;
|
}
|
|
public void setBottomSpace(int bottomSpace) {
|
this.bottomSpace = bottomSpace;
|
}
|
|
public void setHorizontalSpace(int horizontalSpace){
|
rightSpace = leftSpace = horizontalSpace;
|
}
|
public void setVerticalSpace(int verticalSpace){
|
rightSpace = leftSpace = verticalSpace;
|
}
|
|
public void setFirstTop(int firstTop) {
|
this.firstTop = firstTop;
|
}
|
|
public int getLeftSpace() {
|
return leftSpace;
|
}
|
|
public int getRightSpace() {
|
return rightSpace;
|
}
|
|
public int getTopSpace() {
|
return topSpace;
|
}
|
|
public int getBottomSpace() {
|
return bottomSpace;
|
}
|
|
public int getFirstTop() {
|
return firstTop;
|
}
|
}
|