android - Android 中带有视差效果的 RecyclerView 上面的内容

标签 android android-recyclerview parallax android-appbarlayout

1 中所述,我想实现一个布局,其中一半屏幕是一些内容,例如包含饼图的 LinearLayout。 屏幕的另一半应该是一个 RecyclerView ,其中包括我已经实现的 CardView 。 向上滚动时,应该有一个视差效果将Content隐藏到AppBar

我尝试将LinearLayouts(其中一个包含Content,一个包含Recyclerview)与weightSum一起使用> 但它无法正常工作。

我怎样才能正确实现这个?

Design that I want to implement in my App

最佳答案

我同意这里的另一个答案。查看文档。

但是为了快速修复,

首先导入android设计库

implementation 'com.android.support:design:28.0.0'

您必须已经拥有 CardView 和 RecyclerView 库

implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

然后实现这段代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main3Activity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing"
            android:layout_width="match_parent"
            android:layout_height="350dp"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="#0e0d0e"
            app:expandedTitleTextAppearance="@android:color/transparent">

            <!--these views are only to illustrate the imp. tags -->
            <!--that you need to implement in your views-->
            <!--in the "Component" area-->

            <!--start example-->

            <ImageView
                android:id="@+id/iv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@null"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                app:title="Title"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="parallax"/>

            <!--end example-->

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>


    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScrollView"
        android:clipToPadding="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="1200dp">

            <!--implement the RecyclerView here-->

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical">

            </android.support.v7.widget.RecyclerView>


        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

关于android - Android 中带有视差效果的 RecyclerView 上面的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53798473/

相关文章:

java - 如何根据索引而不是键从 LinkedHashMap 获取值?

android - Glide with android RecyclerView 显示 OutOfMemory 错误 (OOM)

java - 如何在不调用 notifyItemChanged 或 DiffUtil 的情况下更新/刷新 RecyclerView 的特定项目?

android - 使用 UniformSpeedInterpolator 或 AutoScroll RecyclerView 在 Android Recyclerview 中水平自动滚动(从右到左)

ios - tableview 图像上的视差,使用自动布局

html - 使 div 高度适合背景图像高度(具有视差效果)

android - SensorLandscape 的调用方式

java - 我有一个回收器 View ,onRun 将显示,但单击按钮后它将为空,我想设置默认回收器 View

android - 为什么我的可搜索 Activity 的 Intent.getAction() 为空?

javascript - 如何在不同视口(viewport)中定位视差网页中的元素?