2016-07-14 47 views
1

我在一个片段中使用带有RecyclerView的SwipeRefreshLayout。RecyclerView滚动不能在片段中使用SwipeRefreshLayout

RecyclerView不会向下滚动。

这是我的主要活动的布局:

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     > 
     <include 
      layout="@layout/toolbar" /> 
      <!-- Replaced with Fragment --> 
      <LinearLayout 
       android:id="@+id/fragment_placeholder" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" /> 


    </LinearLayout> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/main_menu" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:layout_gravity="start" 
     android:background="@color/white" 
     android:scrollbars="vertical" 
     /> 
</android.support.v4.widget.DrawerLayout> 

这工作得很好 - 该片段有问题的RecyclerView替换的LinearLayout与ID fragment_placeholder你可以在上面看到。

片段布局如下:

<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/swipe_refresh_layout"> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/content_recycler_view" 
       android:layout_width="match_parent 
       android:layout_height="match_parent" /> 
    </android.support.v4.widget.SwipeRefreshLayout> 

轻扫刷新手势工作正常,但如果RecyclerView的含量超过了屏幕尺寸,滚动将无法工作。

我试过设置nestedScrollingEnabled(true),但它也不起作用。

RecyclerView dataView = (RecyclerView) layout.findViewById(R.id.content_recycler_view); 
final RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); 
dataView.setLayoutManager(mLayoutManager); 
adapter = new ListContentAdapter(); 
dataView.setAdapter(adapter); 
dataView.setNestedScrollingEnabled(true); 

这只是滚动,如果我换一个NestedScrollView围绕RecyclerView:

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

但这破坏了RecyclerView的优势,重新使用的意见。 为什么不滚动?

感谢您的帮助!

+0

是加入Nestedscrollview后,它曾经在me.Thank您! –

回答

-1

变化:

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

到:

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

甚至尝试过,没有变化:( – epsilon