zoukankan      html  css  js  c++  java
  • 安卓Design包之AppBar和Toolbar的联用

    前面讲了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>
    

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

  • 相关阅读:
    Spark&Hadoop:scala编写spark任务jar包,运行无法识别main函数,怎么办?
    Linux:krb5
    SqlServer数据库端口默认是1433吗?
    Linux下使用shell实现上传linux下某个目录下所有文件到ftp
    Spark+Hadoop+Hive集群上数据操作记录
    hadoop之 Hadoop2.2.0中HDFS的高可用性实现原理
    虚拟路由冗余协议VRRP
    hadoop 之Hadoop生态系统
    Oracle NoLogging Append 方式减少批量insert的redo_size
    Oracle常用的性能诊断语句
  • 原文地址:https://www.cnblogs.com/liushilin/p/5671999.html
Copyright © 2011-2022 走看看