2017-08-17 89 views
1

我有一個回填視圖,填充頂部和底部爲10dp。Recyclerview scrollbar cliptoPadding false?

而我添加clipToPadding = false

像這樣。

<android.support.v7.widget.RecyclerView 
    android:id="@+id/contentView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingStart="@dimen/margin_medium" 
    android:paddingTop="@dimen/margin_medium" 
    android:paddingBottom="@dimen/margin_medium" 
    android:clipToPadding="false" 
    android:scrollbarAlwaysDrawVerticalTrack="true" 
    android:scrollbars="vertical" /> 

我注意到我的滾動條實際上​​會尊重頂部和底部填充,並且不會滾動整個高度。

有沒有辦法讓我的滾動條實際上​​完全滾動頂部和底部?

感謝

回答

-1

這個最快的解決將是選擇在上RecyclerView新的快速滾動條:

按照該文檔的版本26.0.0:

新fastScrollEnabled RecyclerView的布爾標誌。如果啓用,則必須設置fastScrollHorizo​​ntalThumbDrawable,fastScrollHorizo​​ntalTrackDrawable, fastScrollVerticalThumbDrawable和fastScrollVerticalTrackDrawable 。

所以安裝兩個文件:

track_drawable.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@color/state_normal_track" /> 
</selector> 

thumb_drawable.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" android:drawable="@color/colorAccent" /> 
    <item android:drawable="@color/state_normal_scrollbar_thumb" /> 
</selector> 

,這裏是我使用的顏色:

<!-- Fast Scroll track state colors --> 
<color name="state_normal_track">#EEEEEE</color> 

<!-- Scroll Bar thumb state colors --> 
<color name="state_normal_scrollbar_thumb">#9E9E9E</color> 

最後您RecyclerView:

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="10dp" 
    android:paddingStart="10dp" 
    android:paddingTop="10dp" 
    android:paddingBottom="10dp" 
    android:clipToPadding="false" 
    app:fastScrollEnabled="true" 
    app:fastScrollVerticalTrackDrawable="@drawable/vertical_track_drawable" 
    app:fastScrollHorizontalTrackDrawable="@drawable/vertical_track_drawable" 
    app:fastScrollVerticalThumbDrawable="@drawable/vertical_thumb_drawable" 
    app:fastScrollHorizontalThumbDrawable="@drawable/vertical_thumb_drawable" /> 

祝你好運和快樂編碼!