2016-01-15 26 views
7

Trong hoạt động của tôi, tôi có hai RecyclerView s bên trong một ScrollView. Vấn đề là khi tôi vuốt/flick các ScrollView, di chuyển dừng lại ngay lập tức. Có cách nào để có được các ScrollView để thực hiện đà hoặc quán tính vì vậy có một số giảm tốc độ trước khi di chuyển dừng lại?Không có động lượng phát hành bên trong ScrollView

XML của tôi là dưới đây:

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

Trả lời

13

I figured it out! Tất cả những gì tôi phải làm là thiết lập setNestedScrollingEnabled(false); thành hai số RecyclerView và tất cả mọi thứ bắt đầu hoạt động như một sự quyến rũ.

+0

này đã làm việc cho tôi. Tôi có RecyclerView của tôi trong một CollapsingToolbarLayout, và điều này làm việc. –

1

Bạn có thể vô hiệu hóa lồng di chuyển trực tiếp trong XML của bạn với: android:nestedScrollingEnabled="false"

Vì vậy XML của bạn sẽ trông như thế:

<?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> 
Các vấn đề liên quan