Android中具有视差效果的RecyclerView上方的内容
如中所述,我希望实现一种布局,其中一半屏幕是一些Android中具有视差效果的RecyclerView上方的内容,android,android-recyclerview,parallax,android-appbarlayout,Android,Android Recyclerview,Parallax,Android Appbarlayout,如中所述,我希望实现一种布局,其中一半屏幕是一些内容,例如线性布局,包括饼图。 屏幕的另一半应该是一个RecyclerView,包括我已经实现的cardwiew。 向上滚动时,应存在视差效果,将内容隐藏到应用程序栏 我尝试将线性布局(其中一个包括内容,另一个包括回收视图)与权重总和一起使用,但没有正常工作 我怎样才能正确地实现这一点 我同意这里的另一个答案。看看这些文件 但为了快速修复 首先,导入android设计库 implementation 'com.android.support:des
内容
,例如线性布局
,包括饼图。
屏幕的另一半应该是一个RecyclerView
,包括我已经实现的cardwiew
。
向上滚动时,应存在视差效果,将内容
隐藏到应用程序栏
我尝试将线性布局
(其中一个包括内容
,另一个包括回收视图
)与权重总和一起使用,但没有正常工作
我怎样才能正确地实现这一点
我同意这里的另一个答案。看看这些文件
但为了快速修复
首先,导入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>
@MartinZeitler我没有要求具体的代码。我很乐意提供我如何实现它的描述/方法。正如我所写的,我已经尝试了带有布局权重和视差效果的线性布局。我会上传属于那个特定问题的代码,但现在我只有RecyclerView,因为我目前还没有解决这个问题的方法moment@C谢谢,这很好用!尽管我刚刚发现,我最大的问题是不知道如何实现这一点,但更多的是无法正确测试,因为我迁移到了AndroidX和Gradle版本28,其中所有的支持库引用都不起作用。我花了一段时间才找到所有的新图书馆