2015-06-14 25 views
23

tôi bắt đầu sử dụng CoordinatorLayout mới và tôi chạy vào vấn đề này:cuộn xuống trigger làm mới thay vì để lộ thanh công cụ

demo

Như bạn có thể nhìn thấy khi tôi cố gắng để di chuyển xuống khi thanh công cụ là một phần có thể nhìn thấy và recylcerview ở vị trí trên cùng nó kích hoạt sự kiện làm mới thay vì kéo thanh công cụ xuống. Người dùng phải di chuyển lên trên xuống một lần nữa để tiết lộ nó.

Layout XML trông giống như sau: activity_main.xml:

<android.support.v4.widget.DrawerLayout 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: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" 
     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 
       android:id="@+id/toolbar" 
       style="@style/customActionBar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="?attr/colorPrimary" 
       android:minHeight="?attr/actionBarSize" 
       app:layout_scrollFlags="scroll|enterAlways"/> 

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

     <FrameLayout 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@android:color/white" 
     app:headerLayout="@layout/navigation_drawer_header" 
     app:menu="@menu/navigation_items" /> 

</android.support.v4.widget.DrawerLayout> 

fragment_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_refresh" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:clipToPadding="false" 
      android:padding="8dp" 
      android:scrollbars="none" /> 

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

</FrameLayout> 

Ther SwipeRefreshLayout là trong một FrameLayout bởi vì có nhiều yếu tố trong đoạn trong tôi ứng dụng.

Mọi trợ giúp sẽ được đánh giá cao.

+0

có thể trùng lặp của [Android: CollapsingToolbarLayout và SwipeRefreshLayout gặp khó khăn] (http://stackoverflow.com/questions/30779667/android -ollapsingtoolbarlayout-and-swiperefreshlayout-get-stuck) –

+1

[Điều này hiện đã được khắc phục trong Thư viện hỗ trợ v23.1.1 mà không có bất kỳ giải pháp nào] (http://stackoverflow.com/a/33776549/383414) –

+0

@RichardLeMesurier Tôi không nghĩ rằng nó được giải quyết hoàn toàn. Tôi đang đối mặt với những thứ tương tự bằng cách sử dụng phiên bản 23.3. – zgulser

Trả lời

9

CẬP NHẬT: Sự cố này đã được khắc phục trong Thư viện hỗ trợ v23.1.1.

Có vẻ như bạn phải kích hoạt/vô hiệu hóa các SwipeRefreshLayout khi AppBarLayout bù đắp thay đổi, sử dụng AppBarLayout.OnOffsetChangedListener.

Xem https://stackoverflow.com/a/30822119/795820

+0

cũng vui lòng trả lời câu hỏi này: http://stackoverflow.com/questions/36434071/android-support-v4-widget-swiperefreshlayout-working-but-it-is-not-visible –

+1

Mặt sau của nó trong 23.2.1 – k0sh

+0

Cũng dành cho trường hợp lồng nhau RecyclerView, kiểm tra ở đây http://stackoverflow.com/a/36895607/1221256 – user1221256

9

có lẽ đã quá muộn nhưng nó có thể giúp bất kỳ những người mới đến, tôi đã đưa ra một giải pháp dễ dàng cho điều đó. bằng cách tạo ra tùy chỉnh class kéo dài SwipeRefreshLayout bạn có thể sử dụng nó bất cứ nơi nào AppBaLayout tồn tại theo mã bên dưới

public class MySwipeLayout extends SwipeRefreshLayout implements AppBarLayout.OnOffsetChangedListener { 
     private AppBarLayout appBarLayout; 

     public MySwipeLayout(Context context) { 
      super(context); 
     } 

     public MySwipeLayout(Context context, AttributeSet attrs) { 
      super(context, attrs); 
     } 

     @Override 
     protected void onAttachedToWindow() { 
      super.onAttachedToWindow(); 
      if (getContext() instanceof Activity) { 
       appBarLayout = (AppBarLayout) ((Activity) getContext()).findViewById(R.id.appbar); 
       appBarLayout.addOnOffsetChangedListener(this); 
      } 
     } 

     @Override 
     protected void onDetachedFromWindow() { 
      if(appBarLayout!=null){ 
      appBarLayout.removeOnOffsetChangedListener(this); 
      appBarLayout = null; 
      } 
      super.onDetachedFromWindow(); 
     } 

     @Override 
     public void onOffsetChanged(AppBarLayout appBarLayout, int i) { 
      this.setEnabled(i == 0); 
     } 
    } 
+0

Đẹp và sạch sẽ. Cảm ơn. –

+0

@ k0sh vui lòng trả lời câu hỏi này: http://stackoverflow.com/questions/36434071/android-support-v4-widget-swiperefreshlayout-working-but-it-is-not-visible –

+0

Điều này giải quyết được sự cố của tôi –

Các vấn đề liên quan