Sections-decorator-android Introduction

Photo of Paweł Bocheński

Paweł Bocheński

Nov 14, 2018 • 2 min read
susan-yin-647448-unsplash

Have you ever wanted to have a scrolling list with a section title visible all the time? Now you can do it in your own app. Just use our little library Sections-decorator!

It supports vertical and horizontal linear layout manager for Recyclerview and can be easily customized. You can change color and width of the line and TextView that shows your header.

How to use it?

  1. Add jitpack.io to your `build.gradle` project repositories list:

    repositories {
       maven { url 'https://jitpack.io' }
    }
  2. Add library dependency to your app’s module build.gradle dependencies list:

    implementation 'com.github.netguru:sections-decorator-android:0.1.1'
  3. Implement the SectionsAdapterInterface interface in your RecyclerView’s adapter class that tells library how the sections are structured:

    interface SectionsAdapterInterface {
       fun getSectionsCount() : Int
       fun getSectionTitleAt(sectionIndex: Int): String
       fun getItemCountForSection(sectionIndex: Int): Int
    }
    

    The first method returns a number of sections available in adapter. The second one - what are titles for each section, and the last one - how many items are in each section.

  4. Add a SectionDecorator to your recycler view.

    SectionDecorator decorator = new SectionDecorator(getContext());
    decorator.setLineColor(R.color.green)
    decorator.setLineWidth(15f)
    recyclerView.addItemDecoration(decorator);

Et voila:


Summary

The source code is available on Github: https://github.com/netguru/sections-decorator-android

How do you like it? Feel free to contribute to the project and contact us if you have any questions or feedback. We are happy to help and listen to your opinion!

Photo by Susan Yin on Unsplash

Photo of Paweł Bocheński

More posts by this author

Paweł Bocheński

Paweł is a software developer with almost nine years of experience. He started as an embedded...
How to build products fast?  We've just answered the question in our Digital Acceleration Editorial  Sign up to get access

We're Netguru!

At Netguru we specialize in designing, building, shipping and scaling beautiful, usable products with blazing-fast efficiency
Let's talk business!

Trusted by:

  • Vector-5
  • Babbel logo
  • Merc logo
  • Ikea logo
  • Volkswagen logo
  • UBS_Home