Horizontal recyclerView (DiscreteScrollView library) with scaling set to 50% between selected view and others doesn't keep spacing the same. Example below shows that spacing between 1/2 and 4/5 are more spacious than views next to currently selected item on center. It happens gradually by scrolling, for an example going from item 3 to item 2 will be moving item 3/4 apart from each other when onScroll is happening.
spacing between items example I Thought about checking the current width of view when onScroll is happening and programatically reduce the left/right margin by applying new layout params so the space would stay the same.
Trying:
override fun onScroll(
scrollPosition: Float,
currentPosition: Int,
newPosition: Int,
currentHolder: CurrencyAdapter.ViewHolder?,
newCurrent: CurrencyAdapter.ViewHolder?
) {
val layoutParams = currentHolder.layout.layoutParams as ConstraintLayout.LayoutParams
}
}
produces
ClassCastException: androidx.recyclerview.widget.RecyclerView$LayoutParams cannot be cast to androidx.constraintlayout.widget.ConstraintLayout$LayoutParams
1. Is it possible to manipulate layoutParams from within viewHolder?
2. Are there any other options to set fixed spacing?
EDIT: adding DividerItemDecoration shows better where the problem is coming from: DividerItemDecoration
3. Is ItemDecoration the right direction for fixing the issue then?