我为RecyclerView自定义了垂直滚动条,但是用于显示项目位置的拇指有点太大并且在顶部时也有偏移。
在styles.xml中,我定义了使用thumb.xml和track.xml文件的自定义滚动条以实现自定义轨道和拇指。在recyler.xml中,我添加了一个样式属性来显示自定义滚动条,并设置填充。
有什么建议来解决这个问题吗?我尝试更改thumb.xml中的宽度和高度,但无效。谢谢!
样式.xml文件:
<resources>
<style name="AppTheme" parent="@style/Theme.Leanback">
<item name="@attr/scrollbarStyle">@style/scrollbar_shape_style</item>
</style>
<attr name="scrollbarStyle" format="reference"/>
<style name="scrollbar_shape_style">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">false</item>
<item name="android:scrollbarThumbVertical">@drawable/thumb</item>
<item name="android:scrollbarTrackVertical">@drawable/track</item>
<item name="android:scrollbarSize">8dp</item>
</style>
thumb.xml 文件:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="0"
android:endColor="#ffffff"
android:startColor="#ffffff" />
<corners android:radius="5dp" />
<size android:width="8dp" />
<size android:height="3dp" />
track.xml 文件:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="0"
android:endColor="#9BA3C5"
android:startColor="#8388A4" />
<stroke
android:width="7dp"
android:color="#00ffffff"/>
</shape>
回收站的XML文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="383dp"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
style="@style/scrollbar_shape_style"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingEnd="50dp"
android:paddingStart="0dp"/>
</LinearLayout>