在 AppBarLayout 后面滚动 RecyclerView
Scrolling RecyclerView behind a AppBarLayout
我正在尝试在 URL(Google 设计官方网站)上实现 "behavior section" 中的视频效果。这与 Google 照片的效果相同,我猜,在 RecyclerView 的顶部有一个搜索栏 disappear/appear 滚动 up/down
我不知道怎么弄,我从CoordinatorLayout and AppBarLayout开始,但是我无法在AppBarLayout后面看到RecyclerView,它总是保持白色,覆盖RecyclerView如下图(结果和代码[编辑:添加带有布局层的图像])。
或者这是一个习俗 CoordinatorLayout.Behavior ?
如有任何帮助或建议,我们将不胜感激,谢谢
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@android:color/transparent">
<SearchView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/holo_green_light"
android:layout_marginTop="40dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
布局示例
尝试将 CoordinatorLayout 设置为透明
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
这绝对是一种习俗CoordinatorLayout.Behavior。
经过一些搜索和阅读( most important, some inspirations, , and the foundamentals ),我通过以下布局得到了我想要的
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/grid_spacing_header"/>
<SearchView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/searchbar_top"
app:layout_behavior=".SearchBarBehavior"/>
</android.support.design.widget.CoordinatorLayout>
使用我自己的扩展 CoordinatorLayout.Behavior 的 SearchBarBehavior
[代码仍然不完整]
我正在尝试在 URL(Google 设计官方网站)上实现 "behavior section" 中的视频效果。这与 Google 照片的效果相同,我猜,在 RecyclerView 的顶部有一个搜索栏 disappear/appear 滚动 up/down
我不知道怎么弄,我从CoordinatorLayout and AppBarLayout开始,但是我无法在AppBarLayout后面看到RecyclerView,它总是保持白色,覆盖RecyclerView如下图(结果和代码[编辑:添加带有布局层的图像])。
或者这是一个习俗 CoordinatorLayout.Behavior ?
如有任何帮助或建议,我们将不胜感激,谢谢
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@android:color/transparent">
<SearchView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/holo_green_light"
android:layout_marginTop="40dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
布局示例
尝试将 CoordinatorLayout 设置为透明
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
这绝对是一种习俗CoordinatorLayout.Behavior。
经过一些搜索和阅读( most important, some inspirations,
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/grid_spacing_header"/>
<SearchView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/searchbar_top"
app:layout_behavior=".SearchBarBehavior"/>
</android.support.design.widget.CoordinatorLayout>
使用我自己的扩展 CoordinatorLayout.Behavior 的 SearchBarBehavior [代码仍然不完整]