Android RecyclerView滚动无法在片段中使用SwipeRefreshLayout
我正在使用SwipeRefreshLayout和RecyclerView,两者都在片段中 回收视图不会向下滚动 这是我主要活动的布局:Android RecyclerView滚动无法在片段中使用SwipeRefreshLayout,android,android-fragments,android-recyclerview,Android,Android Fragments,Android 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.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>
如果我将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的优势,重新利用了它的视图。
为什么它不滚动
谢谢你的帮助 变化:
<android.support.v7.widget.RecyclerView
android:id="@+id/content_recycler_view"
android:layout_width="match_parent
android:layout_height="match_parent" />
是,添加Nestedscrollview后,它对我有效。谢谢!!!
<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>
<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" />