Sticky ScrollView

Amar Jain
AndroidPub
Published in
1 min readMar 23, 2017

--

One of the very important features of any application is to have layouts which stick either at the top or at the bottom when the user scrolls through the contents. This feature can easily be implemented in web apps using css styling and sticky attributes.

But when it comes to mobile apps, there is no direct way to implement sticky headers or footers for layouts in android.

So I decided to create a library which would implement sticky behaviour with android’s ScrollView. It’s called StickyScrollView.
StickyScrollView provides both sticky header as well as sticky footer.

Sticky Header & Footer with android scrollView

StickyScrollView can be used just like android’s scrollview. All you have to do is to replace your ScrollView in your view’s xml with StickyScrollView and specify the references to the layouts which need to be sticky.

Here is an example of how a StickyScrollView can be used.

<com.amar.library.ui.StickyScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:stickyHeader="@+id/titleLayout"
app:stickyFooter="@+id/buttonLayout">
...
<LinearLayout
android:id="@+id/titleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</LinearLayout>
<LinearLayout
android:id="@+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</LinearLayout>
...
</com.amar.library.ui.StickyScrollView>

More details are available in github.

--

--