Add a sticky header to parallax scrolling - android
Asked Answered
T

2

6

I want to have a parallax scroll in my application much like the spotify app with the 'sticky' header. This means the header will be pinned to the top of the screen. I've found plenty of ScrollView libraries which do these functions separately, I can't find any libraries with do both.

I am using the ParallaxScroll library for the parallex scroll and StickyScrollViewItems to stick the item to the top of the screen.

Any help is much appreciated.

Travesty answered 20/1, 2015 at 10:16 Comment(0)
L
2

visit https://github.com/ksoichiro/Android-ObservableScrollView

If you don't want to use library, you can just get logic of making header sticky from here :-

@Override 
 public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
        if (dragging) {
            int toolbarHeight = mToolbarView.getHeight();
            if (firstScroll) {
                float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView);
                if (-toolbarHeight < currentHeaderTranslationY) {
                    mBaseTranslationY = scrollY;
                } 
            } 
            float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0);
            ViewPropertyAnimator.animate(mHeaderView).cancel();
            ViewHelper.setTranslationY(mHeaderView, headerTranslationY);
        } 
    } 

/// this is the key method to make view sticky.

setTranslationY(float translationY)

Sets the vertical location of this view relative to its top position.

Lamartine answered 20/1, 2015 at 10:29 Comment(0)
E
0

I answering so late, but I hope my answer will help to someone. I also had such a task. I have been looking for answers and examples of sticky header, but for recyclerView. I found the best and simplest solution in the article "Sticky Header For RecyclerView" of Saber Solooki.

enter image description here

Based on this example, I made my contact module for my application, it is very simple.

enter image description here

For parallax scrolling look in this article AppBarLayout scroll behavior with layout_scrollFlags. You can combine both this examples.

Erinerina answered 10/10, 2019 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.