2017-09-25 68 views
0

我有用於回收視圖的自定義垂直滾動條,但用於顯示項目位置的拇指有點過大,並且位於頂部(圖片scroll_2) ,並且我需要按照第一張圖片(圖片scroll_1)上顯示的大小進行尺寸調整。Android如何爲回收視圖製作自定義滾動條

scroll_1, this is how the scroll bar should look scroll_2 is what I get

在styles.xml我定義的thumb.xml和track.xml文件的自定義滾動條定製賽道和拇指。在recyler.xml中,我添加了style屬性以顯示自定義滾動條,並帶有填充。

如何解決這個問題的任何想法,我試圖在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" /> 

Truck.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"/> 

Recycler.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/network_setup_more_recycler" 
    style="@style/scrollbar_shape_style" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:paddingEnd="50dp" 
    android:paddingStart="0dp"/> 

+0

嘗試這個thumb.xml文件: - https://stackoverflow.com/questions/35399829/scrollbar-color-in-recyclerview –

+0

謝謝,我試着但拇指仍然一樣,我仍然有問題的高度 – alezniki

+0

@alezniki:你試過設置 setSmoothScrollbarEnabled - fasle,以編程方式? – Radhey

回答

0

我管理上的滾動條來固定大小的拇指。 下面是固定大小

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:gravity="top"> 
    <shape android:shape="rectangle"> 
     <corners android:radius="100dp" /> 
     <solid android:color="#e9eef2" /> 
     <size 
      android:width="5dp" 
      android:height="25dp" /> 
    </shape> 
</item>