0

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?

ashaneen
  • 137
  • 1
  • 15
  • have you tried using padding in your items? – Mohamed Mohsin Mar 07 '20 at 16:34
  • space is changing gradually when scrolling is happening so using padding as a constant value won't fix the issue – ashaneen Mar 07 '20 at 16:39
  • try to use `DividerItemDecoration` – Sergio Mar 07 '20 at 16:49
  • @Sergey Thanks Sergey for the suggestion, actually applying simple DividerItemDecoration shown very well where are these bounderies coming from. Can You take a look at added image snapshot and suggest if this is the right direction? – ashaneen Mar 07 '20 at 17:00

0 Answers0