2016-01-14 39 views
19

Câu hỏi của tôi là giống như câu hỏi này Scroll behavior in nested RecyclerView with horizontal scrollNested RecyclerView với CoordinatorLayout

Cũng giống như cửa hàng Google Play, tôi có một RecyclerView lồng nhau (ngang) bên trong một RecyclerView mẹ. RecyclerView cha là một con của CoordinatorLayout trong đó thanh công cụ mở rộng và sụp đổ khi cuộn RecyclerView cha mẹ xảy ra.

Tất cả mọi thứ hoạt động tốt trên cảm ứng bên ngoài của đứa trẻ RecyclerView và di chuyển lên CollapsingToolbar bị sụp đổ nhưng khi tôi chạm vào một trong những đứa trẻ RecyclerView và di chuyển lên sau đó phụ huynh RecyclerView được cuộn và CollapsingToolbar không hoạt động.

enter image description here

enter image description here

Nếu yêu cầu sau đó tôi sẽ thêm Mã nguồn của tôi ở đây ..

Bất kỳ trợ giúp sẽ được đánh giá cao !!

UPDATE:

hoạt động của CoordinatorLayout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
android:id="@+id/coord_layout" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".activity.ChannelHubOld"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar_layout" 
    android:fitsSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     app:contentScrim="?attr/colorPrimary" 
     android:fitsSystemWindows="true"> 
     <RelativeLayout 
      android:background="@color/pkDarkGrey" 
      android:fitsSystemWindows="true" 
      android:layout_width="match_parent" 
      android:layout_height="200dp"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       android:src="@drawable/sidebar_header"/> 
     </RelativeLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/my_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?android:attr/actionBarSize" 
      android:theme="@style/ActionBarWidget"/> 

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

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

<!-- Parent RecyclerView ---> 

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

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

Trả lời

32

Có cùng vấn đề. Cố định bằng cách đặt setNestedScrollingEnabled(false) trên RecyclerViews lồng nhau nằm ngang. Có vẻ như cuộn lồng nhau không bị chặn đúng cách bởi CoordinatorLayout.Behavior khi không thiết lập. Hãy thử nó!


Chú ý: bạn cũng phải thêm một hành vi bố trí (ví dụ: app:layout_behavior="@string/appbar_scrolling_view_behavior") vào bên trong (lồng) RecyclerView để làm việc này

+2

yea .. tôi đã giải quyết nó! tôi cần phải áp dụng layoutBehavior trong xml cho NestedRecycler và sau đó setNestedScrollingEnabled thành false. –

+0

@ fast3r Bạn là anh hùng của tôi. Đây phải là một câu trả lời được chấp nhận - hoạt động vừa phải. –

+1

Hoàn hảo! Cảm ơn. – motis10

0

Kiểm tra Creating Collapsing effect. điều này có thể giúp bạn.

mã từ liên kết nếu liên kết bị hỏng.

<android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_scrollFlags="scroll|enterAlways"></android.support.v7.widget.Toolbar> 

</android.support.design.widget.CollapsingToolbarLayout> 
+0

vẫn không có may mắn !! –

+0

thêm cho trình quản lý bố cục như LinearLayoutManager mLayoutManager = new LinearLayoutManager (điều này); // sử dụng trình quản lý bố cục tuyến tính myUpdatedProductsListRecyclerView.setLayoutManager (mLayoutManager); – Harsha

-2

Tôi có giải pháp cho bạn và tôi đã thử cách này gần đây để nó hoạt động.

Bên trong recyclerview của bạn, đặt trong lồng nhauScrollView của bạn thay vì cách khác xung quanh như Scroll behavior in nested RecyclerView with horizontal scroll đề xuất.

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

      <android.support.v4.widget.NestedScrollView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fillViewport="true" 
       > 
      </android.support.v4.widget.NestedScrollView> 

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

hi @Simon Sẽ không ứng dụng gặp sự cố và câu trả lời trong liên kết u đã cung cấp cho biết RecyclerView bên trong NestedScrollView nhưng câu trả lời của bạn là ngược lại với nó. –

+0

Có. Nó ngược lại. Nó sẽ hoạt động. Thử nó. – Simon

+0

đã thử ngay bây giờ. Ứng dụng bị lỗi. Ném: Gây ra bởi: java.lang.IllegalStateException: RecyclerView không có LayoutManager –

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