AppBarLayout

使用之前请在application级别的gradle中添加以下依赖:
compile 'com.android.support:design:24.2.0'

AppBarLayout简介

AppBarLayout 的父类是垂直布局的LinearLayout,它是一个专门为material designs定制的ActionBar控件。
AppBarLayout 的子类应通过

/**在代码中设置*/
AppBarLayout.LayoutParams.setScrollFlags(int flag)
app:layout_scrollFlags="..."//在xml中设置

以下代码来设置它们(子元素)的滚动行为.
AppBarLayout很大程度上是作为CoordinatorLayout控件的子类而存在的,如果你将AppBarLayout作为其他ViewGroup的子类,那么AppBarLayout的大部分功能将无法起作用.
AppBarLayout 需要一个滚动控件通知AppBarLayout 发生了滚动事件,你可以通过ScrollingViewBehavior来监听滚动控件的滚动。

<android.support.design.widget.CoordinatorLayout
           xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:app="http://schemas.android.com/apk/res-auto"
           android:layout_width="match_parent"
           android:layout_height="match_parent">
  
       <android.support.v4.widget.NestedScrollView
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               app:layout_behavior="@string/appbar_scrolling_view_behavior">
  
           <!-- Your scrolling content -->
  
       </android.support.v4.widget.NestedScrollView>
  
       <android.support.design.widget.AppBarLayout
               android:layout_height="wrap_content"
               android:layout_width="match_parent">
  
           <android.support.v7.widget.Toolbar
                   ...
                   app:layout_scrollFlags="scroll|enterAlways"/>
  
           <android.support.design.widget.TabLayout
                   ...
                   app:layout_scrollFlags="scroll|enterAlways"/>
  
       </android.support.design.widget.AppBarLayout>
  
   </android.support.design.widget.CoordinatorLayout>
```


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容