视差滚动背景recyclerview

时间:2016-05-15 17:15:12

标签: android background android-recyclerview parallax

我的recyclerview有一个自定义设计的背景,基本上是为了增加一些设计噪音(比如whatsapp)。 我想要实现的是,当我滚动Recyclerview时,背景会以Recyclerview中项目的一半速度滚动。

任何想法是否可行以及是否,如何去做?

1 个答案:

答案 0 :(得分:2)

这几乎是可以实现的;但是假设您的回收者视图可以垂直滚动10,000像素,您希望将背景翻译成5000像素吗?如果这是那么你将不得不使用一个非常重的图像文件,在你的情况下,大多数定义会耗尽内存。 否则,在frameLayout中保留ScrollView和recycleler视图。 然后在您的活动/片段中添加一个scrollChange监听器到您的recyclerView(这将告诉您回收器视图的位移,尤其是您需要dy)。 根据verticall位移,您可以滚动滚动视图,如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.