Ich benutze ein SwipeRefreshLayout mit einem RecyclerView, beide in einem Fragment.RecyclerView Scrollen funktioniert nicht mit SwipeRefreshLayout in Fragment
Die RecyclerView wird nicht nach unten scrollen.
Dies ist das Layout meiner Haupttätigkeit ist:
<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>
Dies funktioniert gut - das Fragment mit dem problematischen RecyclerView ersetzt das Linearlayout mit der ID fragment_placeholder, denen Sie oben sehen können.
Fragment-Layout ist hier:
<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>
Die Swipe-Refresh-Geste funktioniert gut, aber wenn der Inhalt des RecyclerView die Bildschirmgröße übersteigt, wird nicht funktionieren, das Scrollen.
Ich habe versucht, nestedScrollingEnabled (true) zu setzen, aber es funktioniert auch nicht.
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);
Es nur ist Scrollen, wenn ich eine NestedScrollView um die RecyclerView wickeln:
<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>
Aber das zerstört den Vorteil der RecyclerView, es Ansichten Wiederverwendung. Warum scrollt es nicht?
Danke für Ihre Hilfe!
Ja Nach der Zugabe von Nestedscrollview es für me.Thank Sie gearbeitet !!! –