1. 程式人生 > >解決recyclerview滑動衝突,修復CollapsingToolbarLayout摺疊效果

解決recyclerview滑動衝突,修復CollapsingToolbarLayout摺疊效果

如下圖出現了滑動衝突,尺碼是一個recyclerview 它可以橫向滑動,會把活動時間消費掉.這樣CollapsingToolbarLayout就不會響應摺疊.大的recyclerview就回出現滑動.

解決方案:

/**
 * Enable nested scrolling.
 *
 * <p>This is a delegate method. Call it from your {@link android.view.View View} subclass
 * method/{@link android.support.v4.view.NestedScrollingChild} interface method with the same
 * signature to implement the standard policy.</p>
 *
 * @param enabled true to enable nested scrolling dispatch from this view, false otherwise
 */
public void setNestedScrollingEnabled(boolean enabled) {
    if (mIsNestedScrollingEnabled) {
        ViewCompat.stopNestedScroll(mView);
    }
    mIsNestedScrollingEnabled = enabled;
}

大意:啟用巢狀滾動,引數啟用為true以從此檢視啟用巢狀滾動排程,否則為false

內部巢狀的recyclerview呼叫setNestedScrollingEnabled(false);

就可以解決了.