12

Tôi đang cố gắng triển khai thu phí thu nhỏ bằng thao tác vuốt để làm mới và recyclerview. Khi tôi đang cố gắng cuộn (khi recyclerview chỉ có một mục) thanh công cụ sụp đổ, nhưng khi tôi đang cố gắng cuộn xuống để hiển thị thanh công cụ, điều đó là không thể vì vuốt xuống khiến vuốt vuốt làm mới. Khi recyclerview có nhiều mục nó hoạt động hoàn hảo.Thanh công cụ không hiển thị bằng thao tác vuốt để làm mới

Ai đó có thể giúp tôi không?

Link to gif with problem

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

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="1dp" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:elevation="1dp" 
     android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:layout_scrollFlags="scroll|enterAlways" /> 


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

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/activity_main_swipe_refresh_layout" 
     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/cities_list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

     </android.support.v7.widget.RecyclerView> 

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

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="end|bottom" 
    android:layout_margin="16dp" 
    android:elevation="1dp" 
    android:onClick="addCity" 
    android:src="@drawable/ic_plus_white_36dp" 
    app:borderWidth="0dp" /> 

+0

có thể trùng lặp của [Android: CollapsingToolbarLayout và SwipeRefreshLayout gặp khó khăn] (http://stackoverflow.com/questions/30779667/android-collapsingtoolbarlayout-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) –

Trả lời

14

Cập nhật: Lỗi này đã được sửa trong phiên bản 23.1.1 của thư viện hỗ trợ

Bạn có thể đặt người nghe onOffsetChanged cho AppBarLayout của bạn và ngăn chặn để swipe làm mới cho đến khi bù đắp bố cục AppBarLayout 0.

Điều này đang diễn ra od dụ: https://gist.github.com/blackcj/001a90c7775765ad5212

+0

nó hoạt động cảm ơn. –

+0

Lưu ý rằng lỗi này đã được khắc phục trong phiên bản gần đây của thư viện hỗ trợ (23.1.1 IIRC). –

+1

Tôi cũng đang gặp phải trong '22.2.0' –

0

tôi quản lý nó bằng cách thêm việc thực hiện sau đây của OnOffsetChangedListener trong đoạn:

@Override 
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
    if (collapsingToolbarLayout.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbarLayout)) { 
     swipeRefreshLayout.setEnabled(false); 
    } else { 
     swipeRefreshLayout.setEnabled(true); 
    } 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    appBarLayout.addOnOffsetChangedListener(this); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    appBarLayout.removeOnOffsetChangedListener(this); 
} 
Các vấn đề liên quan