A small android library for tagging views inside a ScrollView as "sticky" making them stick to the top of the scroll container until a new sticky view comes and takes it's place

Overview

StickyScrollViewItems

StickyScrollViewItems is a ScrollView subclass that allowed you to mark items inside the ScrollView as sticky. The items marked as sticky will stick to the top of the ScrollView until another sticky items comes by and pushes it out of the way.

Installing

Add the following gradle dependency exchanging x.x.x for the latest release.

dependencies {
    compile 'se.emilsjolander:StickyScrollViewItems:x.x.x'
}

Usage

First of all replace any instance of ScrollView with StickyScrollView. So you go from this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_height="match_parent" android:layout_width="match_parent">
	<!-- scroll view child goes here -->
</ScrollView>

to this:

<StickyScrollView xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_height="match_parent" android:layout_width="match_parent"
	android:id="@+id/sticky_scroll">
	<!-- scroll view child goes here -->
</StickyScrollView>

As with a regular ScrollView you are only allowed one child. But that child can contain any number of children. It is these children or any of their children that can be tagged as a sticky view. If you want t view to stick to the top when you scroll passed it add a sticky tag with the android:tag attribute to it like this:

<StickyScrollView xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/sticky_scroll"
	android:layout_height="match_parent" android:layout_width="match_parent">

	<LinearLayout 
		android:layout_height="match_parent" android:layout_width="match_parent" 
		android:orientation="horizontal">

		<!-- other children -->

		<View 
			android:layout_height="300dp" 
			android:layout_width="match_parent"
			android:tag="sticky"/>

		<!-- other children -->

	</LinearLayout>

</StickyScrollView>

There are also two additional flags that can be set on views that were added to optimize performance for the most usual cases. If the view you want to stick either has transparency or does not have a constant representation than you must supply one or both of the following flags. -hastransparancy for views that have transparancy and -nonconstant for views that will change appearance during there sticky time (examples are buttons with pressed states as well as progress spinners).

So this ends up with 4 different ways to tag a view as sticky resulting is slightly different behaviour android:tag="sticky" android:tag="sticky-hastransparancy" android:tag="sticky-nonconstant" and android:tag="sticky-hastransparancy-nonconstant".

If you want to add a shadow drawable below the stuck items, you must declare a namespace to find the shadow attributes xmlns:whatever="http://schemas.android.com/apk/res-auto". Usually you do this in the root layout element in you layout.xml file. You can then specify the shadow drawable with whatever:stuckShadowDrawable="" and the shadow height with whatever:stuckShadowHeight="" in xml. Note that when left unspecified, the default shadow height is 10dip.

<StickyScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:whatever="http://schemas.android.com/apk/res-auto"
  android:layout_height="match_parent" android:layout_width="match_parent"
  android:id="@+id/sticky_scroll"
  whatever:stuckShadowDrawable="@drawable/sticky_shadow_default"
  whatever:stuckShadowHeight="50dip" >
  <!-- scroll view child goes here -->
</StickyScrollView>

These shadow height and drawable can also be set programatically. Note that, unlike the xml attribute, setShadowHeight(pixels) only takes the values in pixels.

StickyScrollView stickyScroll = (StickyScrollView) findViewById(R.id.sticky_scroll);
stickyScroll.setShadowDrawable(getResources().getDrawable(
        R.drawable.shadow_drawable));
stickyScroll.setShadowHeight(50); // in pixels
Comments
  • Can't import in Android Studio

    Can't import in Android Studio

    When try to import using android studio 0.3.1

    Got this error No such property: SONATYPE_USERNAME for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

    opened by deckyfx 6
  • Fixed bug with left indent. Added shadow support.

    Fixed bug with left indent. Added shadow support.

    If the sticky view has padding to the left of it, it will now not lose that when it becomes stuck.

    Added ability to set a shadow drawable that is drawn under the sticky heads.

    opened by parkin 4
  • Sticky ScrollView not working after build with Progaurd

    Sticky ScrollView not working after build with Progaurd

    Hello, StickyScrollview working fine when run on devices, but it not working when i generate a build with progaurd. please give some solution note: i also tired this below one -keep class com.emilsjolander.* { ; } -dontwarn com.emilsjolander.

    opened by venkatsaravanan 3
  • Fix: views might be null during onLayout.

    Fix: views might be null during onLayout.

    added flag set to true during onLayout. The flag is used so we don't try to calculate dimensions of a view that might become null during layout (say if we are removing views).

    I was getting this error when I removed views from the ScrollView's child and the get_ForViewRelativeOnlyChild methods were being called. During onLayout, the views that get_ForViewRelativeOnlyChild is trying to calculate the dimensions of might become null. So we should just return zero from get*ForViewRelativeOnlyChild during this time, as the info is likely garbage anyway.

    opened by parkin 3
  • A bug with left indent

    A bug with left indent

    Hi, Emil,

    a great component, thanks for creating it.

    There is a bug in the dispatchDraw(Canvas canvas) method. It should be instead of canvas.translate(getPaddingLeft(), ...

    canvas.translate(getLeftForViewRelativeOnlyChild(currentlyStickingView) + getPaddingLeft(), ...

    The way it is now, if the sticky view is deeper in the hierarchy and to the left, then it jumps when it becomes sticky.

    I am not sure if this calculation should be in the draw method or precalculated somehow, but definitely the left indent of parents needs to be taken into account when translating.

    Thanks!

    opened by andreypetrov 3
  • Upgrade project to work with latest Gradle version

    Upgrade project to work with latest Gradle version

    Upgraded Gradle and fixed the project directory structure to match what is expected. Some more information is available here: tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0

    opened by michaeltweed 2
  • Mavenized project.

    Mavenized project.

    • We use Maven to handle dependencies in our project, so now the library supports it.
    • We needed the library artifact to be downloadable, so I created a Maven repository using github as described here: http://stackoverflow.com/questions/14013644/hosting-a-maven-repository-on-github. Right now that repository is hosted on my github account, but you can easily create one for your account and change POMs accordingly.
    opened by futtetennista 2
  • can't disable auto scroll

    can't disable auto scroll

    Hi, i am working on a page using this nice library. i have a page using StickyScrollView. above this view is a large view to show something important (next i will call it 'header'). what i get now is, every time this view show up (onCreate, onResume), the StickyScrollView do auto scroll to the bottom of the scrollview so the header is now disappear. can i disable auto scroll so the stickyscrollview only scroll manually by the user?

    here i attach the image to visualize the issue

    disable auto scroll

    thankyou *sorry for my bed english

    opened by RahmatNS 1
  • Sticky Item at the back

    Sticky Item at the back

    I'd like to make a layout, on which there is a ScrollView with one sticky item, but next items are scrolling over the sticky item, not below - is it doable?

    opened by emce 1
  • Sticking Tab Layout in a NestedScrollView

    Sticking Tab Layout in a NestedScrollView

    I've used sticky tag for tab layout in my NestedScrollView, but even when the tab layout is stuck I am not able to use horizontal scroll of tab layout

    opened by therealshabi 0
  • Extra spacing is showing at the bottom of the Scrollview

    Extra spacing is showing at the bottom of the Scrollview

    <com.emilsjolander.components.StickyScrollViewItems.StickyScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/parentScroolView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight=".2"
            android:background="@color/gift_vouchr_header_img"
            android:gravity="center">
            <ImageView
                android:id="@+id/imageview_gift"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/splash"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:background="@color/lvb_divider_color"
            android:layout_height="0dip"
            android:layout_weight=".8"
            android:orientation="vertical">
            <android.support.design.widget.TabLayout
                android:id="@+id/common_tablayout"
                style="@style/VoucherTabLayoutStyle"
                android:layout_width="match_parent"
                app:tabGravity="fill"
                app:tabMode="fixed"
                android:layout_height="@dimen/margin_48"
                android:tag="sticky">
            </android.support.design.widget.TabLayout>
    
    
        <android.support.v4.view.ViewPager
            android:id="@+id/common_viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </android.support.v4.view.ViewPager>
        </LinearLayout>
    </LinearLayout>
    
    ![screenshot_20181106-171956](https://user-images.githubusercontent.com/10252363/48063023-c4316080-e1e9-11e8-803f-d8a793751ecd.png)
    opened by amitranjan0007 0
Releases(1.1.0)
Owner
Emil Sjölander
Emil Sjölander
This is a very simple library for Android that allows you to stick an header to a scrollable view and easily apply animation to it

StikkyHeader This is a very simple library for Android that allows you to stick an header to a ListView and easily apply animation to it Usage To use

Carlo Marinangeli 847 Dec 30, 2022
Android library to observe scroll events on scrollable views.

Android-ObservableScrollView Android library to observe scroll events on scrollable views. It's easy to interact with the Toolbar introduced in Androi

Soichiro Kashima 9.6k Dec 30, 2022
An Android custom ListView and ScrollView with pull to zoom-in.

PullZoomView An Android custom ListView and ScrollView with pull to zoom-in. Features Set ZoomView enable Add HeaderView Custom ZoomView Parallax or N

Frank-Zhu 2.3k Dec 26, 2022
Parallax ScrollView and ListView for Android

Parallax Scrolls Parallax ListView and ScrollView for Android This project includes ScrollView with one or more parallaxed views ListView with paralla

Nir Hartmann 851 Dec 3, 2022
A tiling scrollview to display large picture (similar to iOS "CATiledLayer")

Project is not maintained right now. Please see the note at the end of this file. Introduction This Android widget aims to provide a scalable way to d

Sebastian Roth 245 Nov 25, 2022
Android library to display a ListView whose cells are not rigid but flabby and react to ListView scroll.

FlabbyListView This library is not maintained anymore and there will be no further releases Android library to display a ListView which cells are not

JPARDOGO 762 Nov 23, 2022
An open source Android library that provides a floating group view at the top of the ExpandableListView

FloatingGroupExpandableListView FloatingGroupExpandableListView is a huge name an open source Android library that provides a floating group view (aka

Diego Lima 376 Nov 28, 2022
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
Scroll + discover = DiscrollView

Discrollview Regularly, I am pleasantly surprised by websites using a pattern I called the discrollver pattern. I'm sure you already know what I'm tal

Flavien Laurent 1.5k Dec 29, 2022
Android ListView with sticky headers

DEPRECATED HeaderListView is deprecated. No new development will be taking place. Quickstart Import the HeaderListView module in your Android Studio p

Applidium 314 Nov 10, 2022
Android widget with pull to refresh for all the views,and support loadMore for ListView , RecyclerView, GridView and SwipeRefreshLayout.

CommonPullToRefresh Android widget with pull to refresh for all the views,and support loadMore for ListView,RecyclerView,GridView and SwipeRefreshLayo

null 1.1k Nov 10, 2022
A better ExpandableListView, with animated expandable views for each list item

SlideExpandableListView for Android Not happy with the Android ExpandableListView android offers? Want something like the Spotify app. This library al

Tjerk Wolterink 2k Dec 22, 2022
Horizontal list view for Android which allows variable items widths

Deprecated This widget is now deprecated and it won't be updated anymore. Use RecyclerView instead Horizontal Variable ListView Horizontal ListView fo

Alessandro Crugnola 862 Nov 15, 2022
StackExpandableView - A custom view that resembles the iOS notification group behavior

StackExpandableView - A custom view that resembles the iOS notification group behavior

Fabio Sassu 155 Dec 15, 2022
Expandable Recyclerview makes it easy to integrate nested recycler view...🔨 📝

SSExpandableRecyclerView Expandable Recyclerview make it easy to integrate nested recyclerview Features Simple and easy to use ( no complex adapter re

Simform Solutions 52 Nov 1, 2022
Android library that allows you to bind a LinearLayout with a ListAdapter.

LinearListView Android library that allows you to bind a LinearLayout with a ListAdapter. Download Gradle: dependencies { compile 'com.github.franki

Francesco Sardo 571 Dec 22, 2022
android custom listview,with interaction pattern load more and pull to refresh to load data dinamically

The first thing that i have to say is render thanks to johannilsson because all the part of pull to refresh listview is based in the code of his repos

Fabian Leon 447 Nov 15, 2022
Bringing extended scrolling features to Android's native ListView and ExpandableListView.

About QuickScroll QuickScroll is a library aimed at creating similar scrolling experiences to the native Contacts app's People view. It has the same s

Andras Kindler 461 Nov 11, 2022
An easy to use Drag & Drop List for Android. Direct replacement of the android ListView.

DragNDropListView DragNDropListView is a direct replacement for the stock Android ListView. If you know how to use ListView, you already know how to u

null 187 Dec 22, 2022