RecyclerView with items of different height: Scrollbar

前端 未结 4 1898
孤独总比滥情好
孤独总比滥情好 2020-12-31 03:55

I have a RecyclerView with items of varying heights with a scrollbar. Because of the different heights of the items, the scrollbar changes it\'s vertical size,

4条回答
  •  孤独总比滥情好
    2020-12-31 04:41

    Use item positions as metric of scroll progress. This will cause your scroll indicator to become a bit jumpy, but at least it will remain fixed-sized.

    There are multiple implementations of custom scroll indicators for RecyclerView. Most double as fast scrollers.

    Here is my own implementation, based on RecyclerViewFastScroller library. Basically, one have to create a custom View subclass, that will be animated, similarly to ScrollView and DrawerLayout:

    • Store current offset
    • During animation offset position of thumb View via View#offset* calls
    • During layout set position based on current offset.

    You probably don't want to start learning all that magic now, just use some existing fast scrolling library (RecyclerViewFastScroller or one of it's clones).

提交回复
热议问题