android – Where should app:layout_behavior be set?

android – Where should app:layout_behavior be set?

Check this link: https://developer.android.com/reference/android/support/design/widget/AppBarLayout.html

n

n

AppBarLayout also requires a separate scrolling sibling in order ton know when to scroll. The binding is done through then AppBarLayout.ScrollingViewBehavior class, meaning that youn should set your scrolling views behavior to be an instance of AppBarLayout.ScrollingViewBehavior. A string resource containing then full class name is available.

n

n

They mentioned about that, it should be the View which will be shown under the AppBarLayout like this:

n

<android.support.design.widget.CoordinatorLayoutn         xmlns_android=http://schemas.android.com/apk/res/androidn         xmlns_app=http://schemas.android.com/apk/res-auton         android_layout_width=match_parentn         android_layout_height=match_parent>nn     <android.support.v4.widget.NestedScrollViewn             android_layout_width=match_parentn             android_layout_height=match_parentn             [email protected]/appbar_scrolling_view_behavior>nn         <!-- Your scrolling content -->nn     </android.support.v4.widget.NestedScrollView>nn     <android.support.design.widget.AppBarLayoutn             android_layout_height=wrap_contentn             android_layout_width=match_parent>nn         <android.support.v7.widget.Toolbarn                 ...n                 app_layout_scrollFlags=scroll|enterAlways/>nn         <android.support.design.widget.TabLayoutn                 ...n                 app_layout_scrollFlags=scroll|enterAlways/>nn     </android.support.design.widget.AppBarLayout>nn </android.support.design.widget.CoordinatorLayout>n

n


n

n

My question is: in what exact ViewGroup (or maybe View) should we putn that app:layout_behavior?

n

n

And in this link: http://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

n

n

Next, we need to define an association between the AppBarLayout andn the View that will be scrolled. Add an app:layout_behavior to an RecyclerView or any other View capable of nested scrolling such asn NestedScrollView. The support library contains a special stringn resource @string/appbar_scrolling_view_behavior that maps ton AppBarLayout.ScrollingViewBehavior, which is used to notify then AppBarLayout when scroll events occur on this particular view. Then behavior must be established on the view that triggers the event.

n

Make sure you added the appbar_scrolling_view_behavior field in your String.xml

n

<!-- The class name to the ScrollingChildBehavior required for AppBarLayout -->n<string name=appbar_scrolling_view_behavior translatable=false>android.support.design.widget.AppBarLayout$ScrollingViewBehavior</string>n

n

And as everyone knows we just can use this like below

n

<android.support.v7.widget.RecyclerViewn        [email protected]+id/rvSomeListn        android_layout_width=match_parentn        android_layout_height=match_parentn        [email protected]/appbar_scrolling_view_behavior />n

n

Its just for info not OP answer.

android – Where should app:layout_behavior be set?

app:layout_behavior should be set to those views which are direct child of Coordinator layout

Leave a Reply

Your email address will not be published.