2016-01-15 13 views
7

Nella mia attività, ho due RecyclerView s all'interno di uno ScrollView. Il problema è che quando faccio scorrere/sfogliare lo ScrollView, lo scorrimento si interrompe immediatamente. C'è un modo per ottenere il ScrollView per implementare quantità di moto o inerzia, quindi c'è qualche decelerazione prima che lo scorrimento si arresti?Nessun impulso di rilascio all'interno di ScrollView

mio XML è qui sotto:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<ProgressBar 
    android:id="@+id/threadload_progress" 
    style="?android:attr/progressBarStyleLarge" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="8dp" 
    android:visibility="gone" /> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/subforums" 
     android:name="net.polunom.forum.fragments.ThreadFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layoutManager="LinearLayoutManager" 
     tools:context=".fragments.ThreadFragment" 
     tools:listitem="@layout/fragment_subforum"/> 

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/threadlist" 
     android:name="net.polunom.forum.fragments.ThreadFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layoutManager="LinearLayoutManager" 
     tools:context=".fragments.ThreadFragment" 
     tools:listitem="@layout/fragment_thread"/> 

</LinearLayout> 
</ScrollView> 

risposta

13

ho capito! Tutto quello che dovevo fare era impostare setNestedScrollingEnabled(false); sui due RecyclerView s, e tutto iniziò a funzionare come un incantesimo.

+0

Questo ha funzionato per me. Ho il mio RecyclerView all'interno di un CollapsingToolbarLayout, e questo ha funzionato. –

1

è possibile disattivare lo scorrimento annidato direttamente in XML con: android:nestedScrollingEnabled="false"

Così il vostro XML sarà simile:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<ProgressBar 
    android:id="@+id/threadload_progress" 
    style="?android:attr/progressBarStyleLarge" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="8dp" 
    android:visibility="gone" /> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/subforums" 
     android:nestedScrollingEnabled="false" 
     android:name="net.polunom.forum.fragments.ThreadFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layoutManager="LinearLayoutManager" 
     tools:context=".fragments.ThreadFragment" 
     tools:listitem="@layout/fragment_subforum"/> 

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/threadlist" 
     android:nestedScrollingEnabled="false" 
     android:name="net.polunom.forum.fragments.ThreadFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layoutManager="LinearLayoutManager" 
     tools:context=".fragments.ThreadFragment" 
     tools:listitem="@layout/fragment_thread"/> 

</LinearLayout> 
</ScrollView>