2

I'm using layout structure similar to Google Play app. But in my case, I have fixed horizontal RecyclerView containers so I prefer to use NestedScrollView as the root view. 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. How can I remove that scroll conflicts to make my layout scroll smooth like in Google Play app?

Near1999
  • 1,547
  • 2
  • 18
  • 37

1 Answers1

-1

I have also designed an app similer to GooglePlay app. Just follow below steps:

  1. Add attribute app:layout_behavior="@string/appbar_scrolling_view_behavior" to 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
  3. Inside RelativeLayout, add a vertical LinearLayout as a container of all Header view(TextView) and 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~

Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
  • You know what for appbar_scrolling_view_behavior is used? Why you all recomend me to use it? I didnt write that I have an app bar or maybe this layout is fragment layout whitch container already has this attr – Near1999 Mar 28 '17 at 04:44
  • @Near1999: AppBarLayout.ScrollingViewBehavior is used to notify the AppBarLayout when scroll events occur on this particular view. The behavior must be established on the view that triggers the event. – Ferdous Ahamed Mar 28 '17 at 05:11
  • For example: When a CoordinatorLayout notices this attribute declared in the RecyclerView, it will search across the other views contained within it for any related views associated by the behavior. In this particular case, the AppBarLayout.ScrollingViewBehavior describes a dependency between the RecyclerView and AppBarLayout. Any scroll events to the RecyclerView should trigger changes to the AppBarLayout layout or any views contained within it. – Ferdous Ahamed Mar 28 '17 at 05:11
  • @Near1999 If your view already has this attribute just ignore. Apply 2 and 3 no. steps. I just added this because i did't know that you already applied this attribute. Thank you~ – Ferdous Ahamed Mar 28 '17 at 05:16
  • This doesn't solve the problem with scroll conflicts – Near1999 Mar 28 '17 at 07:08