How to use fastScrollEnabled in RecyclerView?

后端 未结 4 807
终归单人心
终归单人心 2020-12-15 19:31

I am new to RecyclerView and I want to implement the fast scroll feature in RecyclerView like google contact application and search on the internet and i found that now Andr

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 19:45

    With Support Library 26, we can easily enable fast scrolling for RecyclerView. Let’s get to it!

    Let’s go over each property one by one :

    1. fastScrollEnabled : boolean value to enable the fast scrolling. Setting this as true will require that we provide the following four properties.
    2. fastScrollHorizontalThumbDrawable : A StateListDrawable that will be used to draw the thumb which will be draggable across the horizontal axis.
    3. fastScrollHorizontalTrackDrawable : A StateListDrawable that will be used to draw the line that will represent the scrollbar on horizontal axis.
    4. fastScrollVerticalThumbDrawable : A StateListDrawable that will be used to draw the thumb which will be draggable on vertical axis.
    5. fastScrollVerticalTrackDrawable : A StateListDrawable that will be used to draw the line that will represent the scrollbar on vertical axis.

    add in build.gradle

        dependencies {
        ....
        compile 'com.android.support:design:26.0.1'
        compile 'com.android.support:recyclerview-v7:26.0.1'
        ....
    }
    

    Since Support Library 26 has now been moved to Google’s maven repository, let’s include that in our project level build.gradle

    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }
    

    activity_main.xml

    
    
     
    

    add below four xml file in your drawable folder,

    line_drawable.xml

    
    
        
    
        
    
    

    line.xml

    
    
    
        
    
        
    
    

    thumb_drawable.xml

    
    
        
    
        
    
    

    thumb.xml

    
    
    
        
    
        
    
        
    
    
    

提交回复
热议问题