Giter VIP home page Giter VIP logo

recyclerview.decoration's Introduction

RecyclerView

当前最新版本号:

SpaceItemDecoration

  • 使每个Item之间的距离保持指定的间距
  • 使用方法:
  1. 创建实例、指定间距并添加到RecyclerView即可。
recyclerView.addItemDecoration(SpaceItemDecoration(8.dp))

StickyItemDecoration

  • 在指定的Item顶部添加跟随Item滚动的悬浮视图。
  • 使用方法:
  1. 在RecyclerView.Adapter的实现类上实现StickySupport接口。
class ItemAdapter : PagingBindingAdapter<NumberItem, NumberItemBindingHolder, NumberViewBinding>(::NumberItemBindingHolder), StickySupport {
    /** 如果某个Position上的Item需要显示悬浮视图,则返回true */
    override fun isSticky(position: Int): Boolean {
        val previous = (position - 1).toString()
        val current = position.toString()
        return position == 0 || current.length > 1 && current.first() != previous.first()
    }

    /** 根据position创建要显示的悬浮视图 */
    override fun createStickyView(position: Int, parent: ViewGroup): View {
        val textView = TextView(parent.context)
        val itemString = position.toString()
        textView.text = if (itemString.length == 1) "0" else itemString.first().toString()
        textView.setPadding(24)
        val typedValue = TypedValue()
        parent.context.theme.resolveAttribute(R.attr.colorSecondary, typedValue, true)
        textView.setBackgroundColor(typedValue.data)
        return textView
    }
}
  1. 在RecyclerView上添加StickyItemDecoration即可
recyclerView.addItemDecoration(StickyItemDecoration())

image

引入

  1. 在你的android工程的根目录下的build.gradle文件中的适当的位置添加以下代码:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. 在你的android工程中对应的android模块的build.gradle文件中的适当位置添加以下代码:
implementation 'cn.numeron:recyclerview.decoration:latest_version'

recyclerview.decoration's People

Contributors

xiazunyang avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

vovien

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.