我正试图在此URL(Google Design官方网站)的“行为部分”中实现类似视频的效果。我想,这与Google Photo相同的效果是,RecyclerView顶部的搜索栏在向上/向下滚动时消失/出现
我不知道如何获得它,我从CoordinatorLayout和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>
示例布局
答案 0 :(得分:3)
绝对是自定义CoordinatorLayout.Behavior。 经过一些搜索和阅读(most important,some inspirations,more inspirations和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>
使用我自己的SearchBarBehavior,它扩展了CoordinatorLayout.Behavior [代码仍然不完整]
答案 1 :(得分:0)
尝试将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">