簡體   English   中英

Android:如何將 recyclerview 滾動條置於 RecyclerView.ItemDecoration 的前面?

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

正如您在下圖中所看到的,我的滾動條顯示在項目分隔符 / RecyclerView.ItemDecoration后面。 因此,您可以在滾動條上看到看起來很丑的分隔符。 有沒有辦法把滾動條放在前面?

在此處輸入圖像描述

我認為滾動條已經在分隔線的前面,它是半透明的,所以您的分隔線可以顯示出來。

您可以通過android:scrollbarStyle屬性控制滾動條的定位。

此屬性有四個可能的值, insideOverlayinsideInsetoutsideOverlayoutsideInset ,記錄在這里:

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

解決方案 #1:使用outsideOverlayoutsideInset將滾動條放置在內容之外,從而避免重疊。 @ScottStanchfield 的答案在這里提供了有用的信息: android ListView scrollbarStyle

解決方案#2:另一種可能的解決方案是將您的ItemDecoration分隔線修改為在邊緣附近淡出的漸變,避免與滾動條重疊。

定義你的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>

修改插圖和 colors 以滿足您的需求。 插圖將防止與滾動條重疊,漸變允許分隔線向左右邊緣淡出。

解決方案#3:通過屬性android:scrollbarThumbVertical為滾動條使用自定義可繪制對象,並確保此可繪制對象不透明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM