简体   繁体   English

Android:如何将 recyclerview 滚动条置于 RecyclerView.ItemDecoration 的前面?

[英]Android: How to bring recyclerview scrollbar to front over RecyclerView.ItemDecoration?

As you notice in the image below, my scrollbar is showing up behind the item separator / RecyclerView.ItemDecoration .正如您在下图中所看到的,我的滚动条显示在项目分隔符 / RecyclerView.ItemDecoration后面。 So you are able to see the separators over the scrollbar which looks ugly.因此,您可以在滚动条上看到看起来很丑的分隔符。 Is there a way to bring the scrollbar to front?有没有办法把滚动条放在前面?

在此处输入图像描述

I think the scrollbar is already in front of the dividers, it's semi-transparent so your divider shows thru.我认为滚动条已经在分隔线的前面,它是半透明的,所以您的分隔线可以显示出来。

You can control scrollbar positioning via the android:scrollbarStyle property.您可以通过android:scrollbarStyle属性控制滚动条的定位。

This property has four possible values, insideOverlay , insideInset , outsideOverlay , outsideInset , documented here:此属性有四个可能的值, insideOverlayinsideInsetoutsideOverlayoutsideInset ,记录在这里:

http://developer.android.com/reference/android/view/View.html#attr_android:scrollbarStyle http://developer.android.com/reference/android/view/View.html#attr_android:scrollbarStyle

SOLUTION #1: Use either outsideOverlay or outsideInset to place the scrollbar outside of your content, thus avoiding the overlapping.解决方案 #1:使用outsideOverlayoutsideInset将滚动条放置在内容之外,从而避免重叠。 The @ScottStanchfield answer here provides useful info on this: android ListView scrollbarStyle . @ScottStanchfield 的答案在这里提供了有用的信息: android ListView scrollbarStyle

SOLUTION #2: Another possible solution is to modify your ItemDecoration divider to a gradient that fades out near the edges, avoiding any overlap with the scrollbar.解决方案#2:另一种可能的解决方案是将您的ItemDecoration分隔线修改为在边缘附近淡出的渐变,避免与滚动条重叠。

Define your divider.xml as follows:定义你的divider.xml如下:

<inset xmlns:android="https://schemas.android.com/apk/res/android"
    android:insetLeft="16dp" android:insetRight="16dp">
    <shape android:shape="rectangle">
        <gradient android:startColor="#20FF0000" android:centerColor="#FFFF0000" android:endColor="#20FF0000" android:angle="0" />
    </shape>
</inset>

modifying the insets and colors to suite your needs.修改插图和 colors 以满足您的需求。 The insets will prevent the overlap with the scrollbars, the gradient allows the divider to fade out towards the left and right edges.插图将防止与滚动条重叠,渐变允许分隔线向左右边缘淡出。

SOLUTION #3: Use a custom drawable for the scrollbar via property android:scrollbarThumbVertical , and ensure this drawable is non-transparent.解决方案#3:通过属性android:scrollbarThumbVertical为滚动条使用自定义可绘制对象,并确保此可绘制对象不透明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM