RecyclerView 快速滚动拇指高度对于大数据集来说太小了 [英] RecyclerView fast scroll thumb height too small for large data set

查看:18
本文介绍了RecyclerView 快速滚动拇指高度对于大数据集来说太小了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用默认的 RecyclerView 快速滚动,并且我遵循了本指南来支持它.

I am using the default RecyclerView fast scroll and I followed this guide to support it.

现在,问题是拇指根据数据集的大小调整其高度.对于 100 及以上的大型项目,拇指会变得非常小,几乎难以响应拖动.

Now, the problem is that the thumb resizes its height as per the size of the data set. For large items like 100 and above, the thumb becomes very small and almost becomes difficult to respond to dragging.

请问有什么办法可以设置快速滚动拇指的最小高度.

Please is there any way I can set minimum height for the fast scroll thumb.

推荐答案

我通过从android.support.v7.widget.FastScroller

I solved this problem by copying the FastScroller class from android.support.v7.widget.FastScroller

然后我从xml中删除了启用的快速滚动并使用以下代码应用了fastscroller:

Then I removed the fast scroll enabled from the xml and applied fastscroller using the below code:

StateListDrawable verticalThumbDrawable = (StateListDrawable) getResources().getDrawable(R.drawable.fastscroll_sunnah);
Drawable verticalTrackDrawable = getResources().getDrawable(R.drawable.fastscroll_line_drawable);
StateListDrawable horizontalThumbDrawable = (StateListDrawable)getResources().getDrawable(R.drawable.fastscroll_sunnah);
Drawable horizontalTrackDrawable = getResources().getDrawable(R.drawable.fastscroll_line_drawable);

Resources resources = getContext().getResources();
new FastScroller(recyclerView, verticalThumbDrawable, verticalTrackDrawable,
                horizontalThumbDrawable, horizontalTrackDrawable,
                resources.getDimensionPixelSize(R.dimen.fastscroll_default_thickness),
                resources.getDimensionPixelSize(R.dimen.fastscroll_minimum_range),
                resources.getDimensionPixelOffset(R.dimen.fastscroll_margin));

在 FastScroller 类中我扩展了 defaultWidth:

Inside the FastScroller Class I extended the defaultWidth:

FastScroller(RecyclerView recyclerView, StateListDrawable verticalThumbDrawable,
        Drawable verticalTrackDrawable, StateListDrawable horizontalThumbDrawable,
        Drawable horizontalTrackDrawable, int defaultWidth, int scrollbarMinimumRange,
        int margin) {
    ...
    this.defaultWidth = defaultWidth;
    ...

然后我更新了这个方法中的代码:

Then I updated the code in this method:

void updateScrollPosition(int offsetX, int offsetY) {
...
mVerticalThumbHeight = Math.max(defaultWidth * 4, Math.min(verticalVisibleLength,
                (verticalVisibleLength * verticalVisibleLength) / verticalContentLength));
...
...
mHorizontalThumbWidth = Math.max(defaultWidth * 4, Math.min(horizontalVisibleLength,
                (horizontalVisibleLength * horizontalVisibleLength) / horizontalContentLength));
...    
}

这可确保最小拇指高度/宽度是默认宽度的 4 倍.

This ensures that the minimum thumb height/width is 4 times the default width.

这篇关于RecyclerView 快速滚动拇指高度对于大数据集来说太小了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆