2016-06-22 17 views
7

Tôi có một hoạt động với thanh công cụ thu gọn và chế độ xem cuộn lồng nhau với FrameLayout mà tôi đặt các mảnh trong đó. Ban đầu, tôi đặt trong đó FragmentA với CardView.RecyclerView bên trong SwipeRefreshLayout bên trong NestedScrollViewLayout không thể cuộn

Hoạt động tuyệt vời. Khi tôi nhấp vào một nút mặc dù tôi thay thế số FragmentB bằng một nút khác có chứa RecyclerView.

Khi tôi thêm FragmentB Tôi không thể cuộn xuống cuối danh sách.

Video này cho thấy vấn đề: LINK TO VIDEO

chủ Hoạt động Giao diện:

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


    <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|enterAlwaysCollapsed" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginStart="48dp" 
     app:expandedTitleMarginEnd="64dp"> 

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

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="fill_vertical" 
    android:fillViewport="true" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    > 

    <!-- the layout which will be the content of the activity (which will be hosted inside the drawer (NOT the list of the drawer)) --> 
    <FrameLayout 
     android:id="@+id/frame_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     > 

    </FrameLayout> 

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

FragmentB Layout:

<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/contentView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


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

     android:layout_height="wrap_content" /> 

    <include 
     layout="@layout/view_progress" 
     /> 

    <include 
     layout="@layout/view_retry" 
     /> 

    <!--</LinearLayout>--> 

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

Đã trả lời trong câu trả lời đầu tiên ... – GensaGames

+0

thay đổi quan điểm tái chế của chiều cao để match_parent – SaravInfern

Trả lời

5

Bạn đặt RecyclerView bên trong 012..
Tôi nghĩ rằng giải pháp tốt hơn là có NestedScrollView hoặc RecyclerView nhưng không phải cả hai, vì RecyclerView đã được triển khai NestedScrollingChild.

Tôi có bố cục tương tự trong ứng dụng của mình. Tôi đã làm như vậy - đặt RecyclerView vào FrameLayout và sau đó bên trong NestedScrollView. Nó dừng lại để hoạt động chính xác. Nếu không có NestedScrollView, mọi thứ đều hoạt động tốt.

+0

Vấn đề không phải là 'RecyclerView với NestedScrollview', nhưng 'SwipeRefreshLayout với NestedScrollview'! 'RecyclerView' và' NestedScrollview' có thể hoạt động cùng nhau. –

0

tôi nghĩ đây là vấn đề scrollevent, customview mở rộng ListView hoặc RecycleView. đây là sol của tôi:

public class RewriteListView extends ListView { 


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


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


    public RewriteListView(Context context, AttributeSet attrs, int defStyle) { 
      super(context, attrs, defStyle); 
    } 


    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
      int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 
          MeasureSpec.AT_MOST); 
      super.onMeasure(widthMeasureSpec, expandSpec); 
    } 

}

được hạnh phúc :)

0

Đã trả lời! Hai phần tử cuộn (chẳng hạn như RecycleView và NestedScrollView trong câu hỏi của bạn) không thể làm việc cùng nhau.

Chỉnh sửa bố cục Hoạt động của bạn.

<ParentLayout> 

....... 

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


    <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|enterAlwaysCollapsed" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginStart="48dp" 
     app:expandedTitleMarginEnd="64dp"> 

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

//THIS FRAGMENT WILL BE REPLACED! 
<FrameLayout 
     android:id="@+id/frame_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     > 

    </FrameLayout> 

....... 
</ParentLayout> 

Và hơn theo mặc định, trong chạy đầu tiên của hoạt động này - thay thế FrameLayout trên - để đoạn đầu tiên của bạn với NestedScrollView (Bạn cần phải tạo Fragment mới để thay thế) và sau khi nhấp chuột thay thế để Fragment trong Câu hỏi của bạn.

+2

Vấn đề không phải là 'RecyclerView với NestedScrollview', nhưng' SwipeRefreshLayout với NestedScrollview'! 'RecyclerView' và' NestedScrollview' có thể hoạt động cùng nhau. –

0

Hai điều:

Trước hết bạn không cần phải nhúng chứa đoạn của bạn trong NestedScrollView nếu bạn muốn có một hành vi di chuyển trong hoạt động của bạn.

Đặt FrameLayout trực tiếp vào bố trí điều phối với layout_behavior thuộc tính trong nó, sau đó chỉ cần đặt bất kỳ mảnh vỡ với tiện ích cuộn View (và nó không cần phải có layout_behavior attr).

Vì vậy, trong ví dụ của bạn, bạn cần phải mảnh vỡ:

FragmentA có bố trí với CardView bên NestedScrollView FragmentB với RecyclerView bên SwipeRefreshLayout

vấn đề khác là bạn đặt nhiều hơn thì một đứa trẻ trong SwipeRefreshLayout, và như đã nêu trong tài liệu, chỉ nên có một con trực tiếp. source

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