android - 视差滚动背景recyclerview

标签 android background android-recyclerview parallax

我的 recyclerview 有一个自定义设计的背景,基本上是为了添加一些设计噪音(就像在 Whatsapp 中一样)。 我想要实现的是,当我滚动 recyclerview 时,背景会以 recyclerview 中项目的一半速度随之滚动。

您知道这是否可行吗?如果可行,该怎么做?

最佳答案

这几乎是可以实现的;但是,假设您的回收器 View 可以垂直滚动 10,000 像素,您是否希望背景平移 5000 像素?如果是这样,那么您将不得不使用非常重的图像文件,在您的情况下,这肯定会耗尽内存。 否则,请在frameLayout 内保留ScrollView 和回收器 View 。 然后在您的 Activity/fragment 中添加一个scrollChange监听器到您的recyclerView(这将告诉您回收器 View 的位移,特别是您需要dy)。 根据垂直位移,您可以像这样滚动 ScrollView scrollView.smoothScrollBy(0,dy); xml代码代码如下:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <!--your imageView that is bigger than screen height comes here-->

            </LinearLayout>
        </ScrollView>
        <android.support.v7.widget.RecyclerView
            android:background="@android:color/transparent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </FrameLayout>
</LinearLayout>

Also please feel free to show me your progress and also if you are stuck.

关于android - 视差滚动背景recyclerview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37241313/

相关文章:

java - 在 Activity/fragment 中确认警报对话框后,如何在单击时更新我的​​ RecyclerView 按钮状态?

android - 回收站 View : Using different LayoutManagers and item structure based on screen orientation

java - 我无法将我的 Android 应用程序连接到 MongoDB

android - 不同屏幕尺寸的样式可以不同吗?

android - 使用 C2DM 并安装在多个 Android 手机上的应用程序架构

html - body 溢出背景

css - Firefox 中不显示背景图像

带有内容 div、wordpress 的 css 全宽背景

android - 以编程方式通过应用程序处理 Activity 堆栈

java - findViewById() 在第二个 Activity 中找不到 RecyclerView