【问题标题】:Add a sticky header to parallax scrolling - android为视差滚动添加粘性标题 - android
【发布时间】:2015-01-20 10:16:06
【问题描述】:

我想在我的应用程序中有一个视差滚动,就像带有“粘性”标题的 spotify 应用程序一样。这意味着标题将固定在屏幕顶部。我发现很多 ScrollView 库分别执行这些功能,但我找不到任何同时执行这两个功能的库。

我正在使用ParallaxScroll 库进行视差滚动,并使用StickyScrollViewItems 将项目粘贴到屏幕顶部。

非常感谢任何帮助。

【问题讨论】:

    标签: android parallax android-scrollview sticky


    【解决方案1】:

    访问https://github.com/ksoichiro/Android-ObservableScrollView

    如果你不想使用库,你可以从这里获取使标题保持粘性的逻辑:-

    @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);
            } 
        } 
    

    /// 这是使视图具有粘性的关键方法。

    setTranslationY(float translationY)
    

    设置此视图相对于其顶部位置的垂直位置。

    【讨论】:

      【解决方案2】:

      我这么晚才回答,但我希望我的回答对某人有所帮助。我也有这样的任务。我一直在寻找粘性标题的答案和示例,但对于 recyclerView。我在 Sabre Solooki 的文章"Sticky Header For RecyclerView" 中找到了最好最简单的解决方案。

      基于这个例子,我为我的应用制作了我的联系人模块,非常简单。

      对于视差滚动查看这篇文章AppBarLayout scroll behavior with layout_scrollFlags。您可以结合这两个示例。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-30
        • 1970-01-01
        • 2019-08-17
        相关资源
        最近更新 更多