【发布时间】:2017-09-25 10:26:34
【问题描述】:
我有一个用于回收站视图的自定义垂直滚动条,但是用于显示项目位置的拇指有点太大,并且在顶部时处于关闭位置。
在styles.xml 中,我使用thumb.xml 和track.xml 文件定义了自定义滚动条,用于自定义轨道和缩略图。在 recyler.xml 中,我添加了一个样式属性来显示自定义滚动条以及填充。
关于如何解决此问题的任何想法,我尝试更改 thumb.xml 中的宽度和高度,但它不起作用。谢谢!
Styles.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>
【问题讨论】:
-
谢谢,我试过了,但拇指还是一样,我的身高还是有问题
-
@alezniki :您是否尝试过设置 setSmoothScrollbarEnabled - fasle ,以编程方式?
-
是的,谢谢,还是不行。
-
是否有任何 RecyclerView 方法可以为跟踪拇指设置固定大小,或者可以覆盖 ScrollView 方法?
标签: android xml scroll android-recyclerview