Skip to content

A scrollview for Android that follows drag path and snaps to the top or bottom.

Notifications You must be signed in to change notification settings

abhriyaroy/SnappingScrollView

Repository files navigation

SnappingScrollView

A custom scrollview implementation for Android that follows drag path and snaps to the top or bottom.

Table of Contents

Introduction

SnappingScrollView serves as an improvement over the default scrollview implementation of android by bringing Bottom Sheet like snapping behaviour to the scrollview.

Sample

Installation

Download

Add the dependency in your app module's build.gradle file

      dependencies {
	         ...
          implementation "com.zebrostudio.snappingscrollview:snappingscrollview:{latest_version}"
        }

Library Details

  • Extends the scrollview class
  • Min sdk 15
  • Written in kotlin
  • Offers disable scroll helper method

Usage Example

Add to your layout in your XML file -

<com.zebrostudio.snappingscrollview.SnappingScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/snappingScrollView"
    android:fillViewport="true">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:background="@color/colorAccent"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:id="@+id/view2"
            android:background="@color/colorPrimaryDark"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:background="@color/colorPrimary"/>
            
         <!-- Other views -->

    </LinearLayout>

</com.zebrostudio.snappingscrollview.SnappingScrollView>

And then in your class file add to you onCreate() or any other lifecycle method -

snappingScrollView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
        override fun onGlobalLayout() {
    	    // Remove the layout listener
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                snappingScrollView.viewTreeObserver.removeOnGlobalLayoutListener(this)
            } else {
                snappingScrollView.viewTreeObserver.removeGlobalOnLayoutListener(this)
            }
	    // Set the view to be snapped on scrolling
            snappingScrollView.setSnappingView(view2)
        }
    })

How to Contribute

Please feel free to raise an Issue/Pr in-case you come across a bug or even if you have any minor suggestion.

About the Author

Abhriya Roy

Android Developer with 2 years of experience in building apps that look and feel great. Enthusiastic towards writing clean and maintainable code. Open source contributor.

LinkedIn   Twitter   Stack Overflow   Angel List   Angel List


License

Copyright 2020 Abhriya Roy

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.

About

A scrollview for Android that follows drag path and snaps to the top or bottom.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages