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

查看:215
本文介绍了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天全站免登陆