Android Activate the scroll of the application control panel based on the return to view.

I have a ViewPager with 2 tabs containing a Recyclerview. I am using support libraries 22.2.0 (AppCompat, Recycler view ...). Originally mymlpager xml:

<android.support.v4.view.ViewPager android:id="@+id/viewPager" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:layout_width="match_parent" android:layout_height="match_parent" /> 

I would like to activate / deactivate the scrolling of the application bar based on each tab / recyclerview, and not based on the whole view, i.e. one tab / recyclerview will scroll the application bar and the other tab / recyclerview will not.

This problem is that when I delete

 app:layout_behavior="@string/appbar_scrolling_view_behavior" 

from the viewpager, by default, layout_behavior is applied to the viewpager, which still activates scrolling the application bar on the / recyclerview tab.

My strategy is to deactivate scrolling of the application bar in the viewpager, perhaps something like this:

  <android.support.v4.view.ViewPager android:id="@+id/viewPager" app:layout_behavior="@string/appbar_desactivated_behavior" android:layout_width="match_parent" android:layout_height="match_parent" /> 

And activate it only on the first tab / recyclerview. Like this:

 <android.support.v7.widget.RecyclerView ... android:id="@+id/playlist1_rv" app:layout_behavior="@string/appbar_scrolling_view_behavior" </android.support.v7.widget.RecyclerView> 

But I need a class for "@ string / appbar_desactivated_behavior". He exists? Is that not so? Or are you thinking of a different strategy? Thanks in advance.

+7
android android-viewpager android-recyclerview android-coordinatorlayout
source share
1 answer

If you are using ViewPager , you must set appbar_scrolling_view_behavior to ViewPager for proper layout.

All you have to do is disable the nested scroll in RecyclerView , which you don't want to scroll through the application bar:

  recyclerview.setNestedScrollingEnabled(false); 

Please note that you may have problems with positioning, and you may have to put the app size mark at the bottom of the recyclerview. And if your user scrolls the application bar with another recyclerview and then iterates over this recyclerview, there will be a space at the bottom of the page.

0
source share

All Articles