简体   繁体   English

RecyclerView滚动与ScrollView冲突

[英]RecyclerView scroll conflicts with ScrollView

I'm using layout structure similar to Google Play app. 我正在使用类似于Google Play应用的布局结构。 But in my case, I have fixed horizontal RecyclerView containers so I prefer to use NestedScrollView as the root view. 但就我而言,我固定了水平RecyclerView容器,因此我更喜欢使用NestedScrollView作为根视图。 Here is my layout structure 这是我的布局结构

<NestedScrollView>

    <HeaderView />
    <RecyclerView />

    <HeaderView />
    <RecyclerView />

    <HeaderView />
    <RecyclerView />

</NestedScrollView>

The problem in that when I scroll vertically NestedScrollView and when it flings I cannot immediately stop it and start scrolling RecyclerView , I need to wait a minute until scroll stops, remove my finger, if it was on the screen, and then try to scroll RecyclerView and vice verse when RecyclerView is scrolling. 问题在于,当我垂直滚动NestedScrollView时,我无法立即停止它并开始滚动RecyclerView ,我需要等待一分钟直到滚动停止,如果手指在屏幕上,请移开手指,然后尝试滚动RecyclerView RecyclerViewRecyclerView滚动时。 How can I remove that scroll conflicts to make my layout scroll smooth like in Google Play app? 如何消除滚动冲突,使布局滚动像Google Play应用一样流畅?

I have also designed an app similer to GooglePlay app. 我还设计了一个类似于GooglePlay应用的应用。 Just follow below steps: 只需执行以下步骤:

  1. Add attribute app:layout_behavior="@string/appbar_scrolling_view_behavior" to android.support.v4.widget.NestedScrollView 将属性app:layout_behavior="@string/appbar_scrolling_view_behavior"android.support.v4.widget.NestedScrollView
  2. Use RelativeLayout as direct child of android.support.v4.widget.NestedScrollView and add attribute android:descendantFocusability="blocksDescendants" to RelativeLayout RelativeLayout用作android.support.v4.widget.NestedScrollView直接子代,并将android:descendantFocusability="blocksDescendants"属性添加到RelativeLayout
  3. Inside RelativeLayout , add a vertical LinearLayout as a container of all Header view( TextView ) and RecyclerView RelativeLayout内部,添加垂直的LinearLayout作为所有Header视图( TextView )和RecyclerView的容器

Here is the structure of working code. 这是工作代码的结构。 Try this: 尝试这个:

<android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.AppBarLayout />

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <!-- Header view -->
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:paddingLeft="16dp"
                    android:gravity="center_vertical"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textColor="@color/textColorSecondary"
                    android:text="Header"/>

                <android.support.v7.widget.RecyclerView />

                <!-- Header view -->
                <TextView />

                <android.support.v7.widget.RecyclerView />

                <!-- Header view -->
                <TextView />

                <android.support.v7.widget.RecyclerView />

                <!-- Header view -->
                <TextView />

                <android.support.v7.widget.RecyclerView />

                <!-- Header view -->
                <TextView />

                <android.support.v7.widget.RecyclerView />

                ................
                ..........................    
            </LinearLayout>
        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Hope this will help you~ 希望对您有帮助〜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM