Where should 'app:layout_behavior' be set?

后端 未结 5 2094
萌比男神i
萌比男神i 2020-12-07 17:39

Should it be set at the AppBarLayout sibling\'s parent or at the first Scrollable View inside its sibling?


With Material Design for Android, there are Views th

5条回答
  •  爱一瞬间的悲伤
    2020-12-07 18:20

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

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

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

    
    
         
    
             
    
         
    
         
    
             
    
             
    
         
    
     
    

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

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

    Next, we need to define an association between the AppBarLayout and the View that will be scrolled. Add an app:layout_behavior to a RecyclerView or any other View capable of nested scrolling such as NestedScrollView. The support library contains a special string resource @string/appbar_scrolling_view_behavior that maps to AppBarLayout.ScrollingViewBehavior, which 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.

提交回复
热议问题