6

我具有使用RecyclerView一個LinearLayoutManagerHORIZONTAL取向,嵌套在FrameLayout內使用BottomSheetBehaviorRecyclerView(水平)嵌套在BottomSheet防止垂直滾動

當試圖在RecyclerView上垂直拖動時,BottomSheet不響應拖動事件。推測這是因爲水平方向的垂直滾動被禁用了LayoutManager

我試過重寫LinearLayoutManager.canScrollVertically()並且返回true。這工程..如果您以非常小心的方式垂直拖動,BottomSheet將作出迴應。只要涉及到任何水平移動,BottomSheet將停止響應垂直拖動事件。

我不確定覆蓋canScrollVertically()是否是正確的方法 - 從用戶體驗的角度來看,它肯定不對。

我也注意到,如果我用一個ViewPager,而不是和水平定向LayoutManager一個RecyclerView,該BottomSheet響應垂直的掠過事件所需。

是否存在的LayoutManager一些其他的方法,RecyclerViewBottomSheet Behavior,要不乾脆東西,可以幫助傳播到BottomSheet Behavior垂直滾動的事件?

有這裏的問題的一個例子:

https://github.com/timusus/bottomsheet-test

只要擴大與第一底片(問題可以與提交#f59a7031被再​​現)。

回答

6

問題在哪裏?在FrameLayoutBottomSheet當放入CoordinatorLayout時可以很好地工作。然後BottomSheet可以將其滾動狀態通過CoordinatorLayout傳遞給作爲CoordinatorLayout的直接子代的其他視圖。

爲什麼RecyclerView無法將滾動狀態傳遞給BottomSheet?它不是CoordinatorLayout的直接子女。但有一種方法可以通過它們:RecyclerView必須注意實施NestedScrollingParentNestedScrollingChild。這個問題的答案是:NestedScrollView

所以你fragment_sheetX.xml佈局應該是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#fff" 
    android:orientation="vertical" 
    android:fillViewport="true"> 

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

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

還要注意android:fillViewport="true"否則,你的RecyclerView不會把整個高度。

但它仍然無法正常工作。爲什麼?必須告知RecyclerView將垂直滾動傳遞給父項。怎麼樣?答案是recyclerView.setNestedScrollingEnabled(false);,但是更好地描述爲here

btw:MultiSheetView是一個很棒的功能和非常有趣的移動UX設計方法。

+0

我懷疑'FRAMELAYOUT'阻止滾動事件傳播到'CoordinatorLayout'。我認爲在某個時候我接近了這個解決方案,但是在視口問題上遇到了麻煩。非常感謝。 –