Custom Cell Space For RecyclerView
May 3, 2019
Here is how we can have custom paddings in between cells for a RecyclerView.
Decoration
First create a custom Decoration object like this:
1 | /** |
The above class will take in a number when init and take that number as the space between the cell.
1 | if (parent.getChildAdapterPosition(view) != (parent.adapter?.itemCount ?: 0) - 1) |
This if statement make sure that we only add this space in between. Exclude the last element in recycler view.
Apply Decoration
Now we have this custom decoration class, the next step is to create the decoration instance and assign to a recycler view.
1 | recyclerView.addItemDecoration(new CustomSpacingDecoration((int) getResources().getDimension(R.dimen.button_account_type_padding_in_between))); |
