Im trying to delete the empty column Item decoration as per the below Image. I Initially thought to restrict the spancount for the last row as per the content using below code in comments but however Im not successful.
below is the code and Image as a result.
val taskDatesView: RecyclerView = binding.taskDatesRecyclerView
val manager = GridLayoutManager(context,10)
taskDatesView.layoutManager = manager
taskDatesView.adapter = taskDatesAdapter
createTasksViewModel.taskDates.observe(viewLifecycleOwner) {
it?.let(taskDatesAdapter::setTaskDates)
val decoration = DividerItemDecoration(context, HORIZONTAL)
taskDatesView.addItemDecoration(decoration)
/*manager.spanSizeLookup = object :SpanSizeLookup(){
override fun getSpanSize(position: Int): Int {
val lastRowCount = (taskDatesAdapter.itemCount%10)
if(position>taskDatesAdapter.itemCount -lastRowCount){
return lastRowCount
}
return 10
}
}*/
when I uncommented the code and run the app below is the result
Any code references or links will be helpful. Thanks in Advance.


Within Custom Divider, modifying the bottom padding based on the lastRowCount it is working as expected.
Below is the working code and result also added comments within code for better understanding
If we need both vertical and horizontal orientations, use above and the below code