Created
August 24, 2015 22:01
-
-
Save mrhether/70ef014109dae77b2827 to your computer and use it in GitHub Desktop.
The following code will handle padding on StaggeredGridLayoutManager, GridLayoutManager, and LinearLayoutManager.
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
import android.graphics.Rect; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.View; | |
/** | |
* Created by markhetherington on 15-08-17. | |
*/ | |
public class SpacesItemDecoration extends RecyclerView.ItemDecoration { | |
private int halfSpace; | |
public SpacesItemDecoration(int space) { | |
this.halfSpace = space / 2; | |
} | |
@Override | |
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { | |
if (parent.getPaddingLeft() != halfSpace) { | |
parent.setPadding(halfSpace, halfSpace, halfSpace, halfSpace); | |
parent.setClipToPadding(false); | |
} | |
outRect.top = halfSpace; | |
outRect.bottom = halfSpace; | |
outRect.left = halfSpace; | |
outRect.right = halfSpace; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment