前面讲了Design包的的CoordinatorLayout和SnackBar的混用,现在继续理解Design包的AppBar;

AppBarLayout跟它的名字一样,把容器类的组件全部作为AppBar.

如:

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:id="@+id/main_toolbar"/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="悬停条目"/> </android.support.design.widget.AppBarLayout>

  

这里就是把Toolbar和TextView放到了AppBarLayout中,让他们当做一个整体作为AppBar。

引用appBar的

app:layout_scrollFlags="scroll|enterAlways"
属性,则可实现下拉的时候不显示appbar,上拉的时候显示appbar。这个在用户交互上真的挺好用的。 再来看看可折叠的ToolBar
 <android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_height="wrap_content">
<!--可折叠的toolbar-->
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_collapseMode="parallax"
android:src="@mipmap/ic_launcher"/> <android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:id="@+id/main_toolbar"/> </android.support.design.widget.CollapsingToolbarLayout> <!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="悬停条目"/>--> </android.support.design.widget.AppBarLayout>

  非常的简单。只需要在上面的代码中修改一下就可以了。

最新文章

  1. MVC5 CodeFirst (一)
  2. 【iCore3 双核心板】例程十:RTC实时时钟实验——显示日期和时间
  3. [原创]java WEB学习笔记95:Hibernate 目录
  4. 在Linux 5/6上使用UDEV SCSI规则配置ASM DISK
  5. python 可变参数
  6. windows下nginx+fastcgi不能使用file_get_contents/curl/fopen的原因
  7. MySQL purge log简单吗
  8. javascript Window对象 第16节
  9. Spring 3 + Quartz 1.8.6 Scheduler Example--reference
  10. DTO学习系列之AutoMapper(四)
  11. 基于注解的EF
  12. Swift构造函数(Initializer)和析构函数(Deinitializer)
  13. python汉字输出编码问题
  14. IEnumerable&lt;T&gt;和IQueryable&lt;T&gt;区分
  15. linux 安装 ftp 实现文件共享
  16. Laravel 中设置 Carbon 的 diffForHumans 方法返回中文
  17. [转]ZooKeeper学习第一期---Zookeeper简单介绍
  18. shell 的有用函数
  19. Ubuntu下使用git提交代码至GitHub
  20. xtrabackup拷贝redolog前做的细节操作

热门文章

  1. Kali对wifi的破解记录
  2. 异步编程 In .NET
  3. 架构设计:远程调用服务架构设计及zookeeper技术详解(下篇)
  4. PHP 5.6 编译安装选项说明
  5. Python列表去重
  6. PHP-解析验证码类--学习笔记
  7. 多线程条件通行工具——AbstractQueuedSynchronizer
  8. 谈谈JS的观察者模式(自定义事件)
  9. LINQ to SQL Select查询
  10. springmvc+bootstrap+jquerymobile完整搭建案例(提供下载地址)