android - 将粘性标题添加到视差滚动 - android

标签 android parallax android-scrollview sticky

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

我正在使用 ParallaxScroll parallex scroll 和 StickyScrollViewItems 的库将项目粘贴到屏幕顶部。

非常感谢任何帮助。

最佳答案

访问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);
        } 
    } 

///这是让 View 具有粘性的关键方法。

setTranslationY(float translationY)

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

关于android - 将粘性标题添加到视差滚动 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28042761/

相关文章:

android - 监控和提高 android 应用程序的 android 性能

java - Android 添加多个 View 到 View 组

android - 如何让一个Activitly正确的观察Lifecycle事件

css - Web 视差滚动背景图像和文本

jquery - 向下滚动页面时向上滑动 div 以显示其后面的内容

android - 尝试在Unity3d中编译 Assets 之一时编译项目卡纸

javascript - 尝试在纯 CSS 视差上使用 JS .scroll()

android - ScrollView 使工具栏在 Pre-Lollipop 设备上消失

android - 如何让谷歌地图在 ScrollView 中正确滚动?

android - ScrollView 内的可滚动多行 TextView(不涉及触摸交互)