timusus / RecyclerView-FastScroll

A simple FastScroller for Android's RecyclerView
Other
1.39k stars 182 forks source link

fixed Item Height obtain that would be a problem? #122

Open negier opened 8 months ago

negier commented 8 months ago

FastScrollRecyclerView#updateThumbPosition

rowCount * scrollPosState.rowHeight

Because some itemView height is not same. I like your smooth effect, but I haven't use your code. So this question only give you look.

negier commented 8 months ago

I find you use fixed ItemHeight to calculate AllHeight, and you use

View view = recyclerView.getChildAt(0);
linearLayoutManager.getDecoratedTop(view); 

But I find some code in internet, may be should be better:

            int range = 0;
            int temp = recyclerView.computeVerticalScrollRange();//整体的高度,注意是整体,包括在显示区域之外的 会动态变化
            if (temp > range) {
                range = temp;
            }
            int offset = recyclerView.computeVerticalScrollOffset();//已经向下滚动的距离,为0时表示已处于顶部。
            int extent = recyclerView.computeVerticalScrollExtent();//RecycleView显示区域的高度。
            float proportion = (float) (offset * 1.0 / (range - extent));//滑动比例

You can use this code optimize your library, I recommand you put this code in onPreDraw listener inner.

Danielnajarn commented 8 months ago

You can use this code optimize your library, I recommand you put this code in onPreDraw listener inner.

Yulldem commented 3 months ago

Great

Yulldem commented 3 months ago

³j