How to setup Unsplash Grid Layout

private fun setupRecyclerView() {
val gridLayoutManager = grid!!.layoutManager as GridLayoutManager?
gridLayoutManager!!.spanSizeLookup = object : SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
/* emulating https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsck9lUkgxNVZza1U/style_imagery_integration_scale1.png */
return when (position % 6) {
5 -> 3
3 -> 2
else -> 1
}
}
}
grid!!.addItemDecoration(
GridMarginDecoration(
resources.getDimensionPixelSize(R.dimen.grid_item_spacing)
)
)
grid!!.setHasFixedSize(true)
}
public class GridMarginDecoration extends RecyclerView.ItemDecoration {

private int space;

public GridMarginDecoration(int space) {
this.space = space;
}

@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.top = space;
outRect.right = space;
outRect.bottom = space;
}
}



Comments