2015-06-03 23 views
36

Próbuję zaimplementować funkcję automatycznego ukrywania paska narzędzi z nowej biblioteki wsparcia 22.2.0. Bez SwipeRefreshLayout działa poprawnie:Android: CoordinatorLayout i SwipeRefreshLayout

enter image description here

Ale kiedy ponownie dodać ten układ, pasek narzędzi pokrywają recyclerview:

enter image description here

Kod:

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.CoordinatorLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:fab="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.v7.widget.Toolbar 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       android:theme="@style/ThemeOverlay.ActionBar" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_scrollFlags="scroll|enterAlways"/> 

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

     <android.support.v4.widget.SwipeRefreshLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/swipe_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/cardList" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

     </android.support.v4.widget.SwipeRefreshLayout> 
    </android.support.design.widget.CoordinatorLayout> 
</android.support.v4.widget.DrawerLayout> 

Na y pomysł, jak to naprawić?

Odpowiedz

79

Ustaw zachowanie przewijania na SwipeRefreshLayout, a nie na RecyclerView.

<android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/cardList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" /> 

    </android.support.v4.widget.SwipeRefreshLayout> 
+2

Dziękujemy! To działa;) – Tomas

+1

Bardzo dziękuję ... – Hani

+1

@ Tomas Chciałbym zapytać, czy zauważyłeś, że jeśli zaczniesz przewijać, dopóki AppBarLayout nie zostanie w pełni rozwinięty (verticalOffset osiągnie 0) i nadal przewijacie pojawia się wskaźnik odświeżania SwipeRefreshLayout, w ten sposób użytkownik będzie mógł również wywołać to działanie. Łatwo to odtworzyć przynajmniej po mojej stronie, mając tylko kilka elementów na ekranie RecyclerView. Każda pomoc będzie bardzo ceniona. –

Powiązane problemy