Created
October 30, 2018 05:46
-
-
Save vishvendra01/ee9e2b56e25aca121ad6cef1e62f8f58 to your computer and use it in GitHub Desktop.
SpacesItemDecoration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scrb.raj.in.citizenservices.utils; | |
import android.graphics.Rect; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.View; | |
public class SpacesItemDecoration extends RecyclerView.ItemDecoration { | |
private int leftSpace; | |
private int topSpace; | |
private int rightSpace; | |
private int bottomSpace; | |
public SpacesItemDecoration(int left, int top, int right, int bottom) { | |
this.leftSpace = left; | |
this.topSpace = top; | |
this.rightSpace = right; | |
this.bottomSpace = bottom; | |
} | |
public SpacesItemDecoration(int space) { | |
this.leftSpace = space; | |
this.topSpace = space; | |
this.rightSpace = space; | |
this.bottomSpace = space; | |
} | |
@Override | |
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { | |
outRect.left = leftSpace; | |
outRect.right = rightSpace; | |
outRect.bottom = bottomSpace; | |
// Add top margin only for the first item to avoid double space between items | |
if (parent.getChildAdapterPosition(view) == 0) { | |
outRect.top = topSpace; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment