Forked from Miha-x64/FirstLastItemSpacesDecoration.java
Created
February 19, 2019 11:34
-
-
Save hasankucuk/5a615dfeac13f0eb6bf0a1c9739ec4fd to your computer and use it in GitHub Desktop.
RecyclerView decoration which adds indentation in the beginning and in the end of content.
This file contains hidden or 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 net.aquadc.commonandroid.lists; | |
import android.graphics.Rect; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.View; | |
public class FirstLastItemSpacesDecoration extends RecyclerView.ItemDecoration { | |
private final int directSpace; | |
private final int reverseSpace; | |
public FirstLastItemSpacesDecoration(int space, boolean layoutReversed) { | |
if (layoutReversed) { | |
directSpace = 0; | |
reverseSpace = space; | |
} else { | |
directSpace = space; | |
reverseSpace = 0; | |
} | |
} | |
@Override | |
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { | |
if (parent.getChildAdapterPosition(view) == state.getItemCount()-1) { | |
outRect.bottom = directSpace; | |
outRect.top = reverseSpace; | |
} | |
if (parent.getChildAdapterPosition(view) == 0) { | |
outRect.bottom = reverseSpace; | |
outRect.top = directSpace; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment