2016-01-15 2 views
7

В моей деятельности у меня есть два RecyclerView s внутри ScrollView. Проблема в том, что когда я прокручиваю/снимаю ScrollView, прокрутка немедленно останавливается. Есть ли способ получить ScrollView, чтобы реализовать импульс или инерцию, поэтому есть некоторое замедление до остановки прокрутки?В ScrollView

Мой XML ниже:

<?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> 

ответ

13

Я понял это! Все, что мне нужно было сделать, было установить setNestedScrollingEnabled(false); двум RecyclerView, и все начинало работать как шарм.

+0

Это работает для меня. У меня есть RecyclerView в CollapsingToolbarLayout, и это сработало. –

1

Вы можете отключить вложенными прокрутки непосредственно в XML с: android:nestedScrollingEnabled="false"

Так что ваш XML будет выглядеть следующим образом:

<?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>