2

Я пытаюсь добиться эффекта, подобного видео в разделе «поведение» на этом URL (официальный сайт Google Design). Это тот же эффект Google Фото, я думаю, с панелью поиска в верхней части RecyclerView, которая исчезает/появляется при прокрутке вверх/внизПрокрутка RecyclerView за AppBarLayout

Я не знаю, как это получить, я начал с CoordinatorLayout10 и AppBarLayout , но я не могу получить RecyclerView, видимый за AppBarLayout, он всегда остается белым, покрывая RecyclerView как показано ниже (результат и код [edit: добавлено изображение с макетом слоев]).

Или это обычай CoordinatorLayout.Behavior?

Любая помощь или предложение будет оценено, спасибо

result

<?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> 

Пример компоновки

enter image description here

+0

Вы имеете в виду сплошную белую границу, которая перекрывает RecyclerView при прокрутке вниз? – GPack

+0

Да, только этот взгляд. Я пытаюсь получить тот же эффект, что указан в документации Google, связанной с вопросом – marco

+0

Попробуйте удалить свойства полей в SearchView и добавить подобные свойства paddings в AppBarLayout. – GPack

ответ

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 [код еще не завершен]

+0

следующее за новостями – GPack

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"> 
+0

Это не работает, но у меня есть более ясная проблема. Это «что-то» под AppBar и над RW (все еще не разрешено, я скоро отредактирую вопрос), спасибо – marco

Смежные вопросы