Add sticky title to parallax scroll - android

I want to have parallax scrolling in my application, as well as a spotify application with a sticky header. This means that the title will be docked at the top of the screen. I found many ScrollView libraries that perform these functions separately, I can not find any libraries with both.

I use the ParallaxScroll library to scroll through parallex and StickyScrollViewItems to stick to the top of the screen.

Any help is greatly appreciated.

+6
source share
2 answers

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

If you do not want to use the library, you can just get the logic of creating a sticky header 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); } } 

/// is the key method to make the look sticky.

 setTranslationY(float translationY) 

Sets the vertical position of this view relative to its upper position.

+2
source

I answer so late, but I hope my answer helps someone. I also had such a task. I was looking for answers and sticky header examples, but for recyclerView. I found the best and easiest solution in the article โ€œSticky heading for RecyclerViewโ€ by Saber Soluki.

enter image description here

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

enter image description here

To scroll through parallax, see the AppBarLayout scroll behavior with layout_scrollFlags in this article. You can combine both of these examples.

0
source

Source: https://habr.com/ru/post/981264/


All Articles