简体   繁体   English

向视差滚动添加粘性标头-android

[英]Add a sticky header to parallax scrolling - android

I want to have a parallax scroll in my application much like the spotify app with the 'sticky' header. 我想在我的应用程序中有一个视差滚动,就像带有'sticky'标头的spotify应用程序一样。 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. 我发现有很多ScrollView库可以单独执行这些功能,但找不到同时使用这两个功能的任何库。

I am using the ParallaxScroll library for the parallex scroll and StickyScrollViewItems to stick the item to the top of the screen. 我正在使用ParallaxScroll库进行parallex滚动和StickyScrollViewItems将项目粘贴到屏幕顶部。

Any help is much appreciated. 任何帮助深表感谢。

visit https://github.com/ksoichiro/Android-ObservableScrollView 访问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. 设置此视图相对于其顶部位置的垂直位置。

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. 我一直在寻找答案和粘性标头的示例,但对于recyclerView。 I found the best and simplest solution in the article "Sticky Header For RecyclerView" of Saber Solooki. 我在Saber Solooki的文章“ RecyclerView的粘性标题”中找到了最好,最简单的解决方案。

在此处输入图片说明

Based on this example, I made my contact module for my application, it is very simple. 基于此示例,我为我的应用程序制作了联系模块,这非常简单。

在此处输入图片说明

For parallax scrolling look in this article AppBarLayout scroll behavior with layout_scrollFlags . 对于视差滚动,请在本文中查看带有layout_scrollFlags的AppBarLayout滚动行为 You can combine both this examples. 您可以将这两个示例结合在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM