Giter Site home page Giter Site logo

gravitysnaphelper's Introduction

GravitySnapHelper

A SnapHelper that snaps a RecyclerView to an edge.

Setup

Add this to your build.gradle:

implementation 'com.github.rubensousa:gravitysnaphelper:2.2.0'

How to use

You can either create a GravitySnapHelper, or use GravitySnapRecyclerView.

If you want to use GravitySnapHelper directly, you just need to create it and attach it to your RecyclerView:

val snapHelper = GravitySnapHelper(Gravity.START)
snapHelper.attachToRecyclerView(recyclerView)

If you want to use GravitySnapRecyclerView, you can use the following xml attributes for customisation:

<attr name="snapGravity" format="enum">
<attr name="snapEnabled" format="boolean" />
<attr name="snapLastItem" format="boolean" />
<attr name="snapToPadding" format="boolean" />
<attr name="snapScrollMsPerInch" format="float" />
<attr name="snapMaxFlingSizeFraction" format="float" />

Example:

<com.github.rubensousa.gravitysnaphelper.GravitySnapRecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:snapGravity="start" />

Start snapping

val snapHelper = GravitySnapHelper(Gravity.START)
snapHelper.attachToRecyclerView(recyclerView)

Center snapping

val snapHelper = GravitySnapHelper(Gravity.CENTER)
snapHelper.attachToRecyclerView(recyclerView)

Limiting fling distance

If you use setMaxFlingSizeFraction or setMaxFlingDistance you can change the maximum fling distance allowed.

With decoration

Features

  1. setMaxFlingDistance or setMaxFlingSizeFraction - changes the max fling distance allowed.
  2. setScrollMsPerInch - changes the scroll speed.
  3. setGravity - changes the gravity of the SnapHelper.
  4. setSnapToPadding - enables snapping to padding (default is false)
  5. smoothScrollToPosition and scrollToPosition
  6. RTL support out of the box

Nested RecyclerViews

Take a look at these blog posts if you're using nested RecyclerViews

  1. Improving scrolling behavior of nested RecyclerViews

  2. Saving scroll state of nested RecyclerViews

License

Copyright 2018 The Android Open Source Project
Copyright 2019 Rúben Sousa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

gravitysnaphelper's People

Contributors

rubensousa avatar supercilex avatar jt-gilkeson avatar

Watchers

James Cloos avatar

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.