zoukankan      html  css  js  c++  java
  • AppBarLayout的基本使用

    在新版本的android api中提供了android.support.desgin.widget包,在其中提供了许多实现了Material Dsign设计的类,可能是gitgub上有太多Material Design的实现,google希望整合一个官方的类库供大家使用才提供了该支持包,并且这些类库可以兼容到android2.1,所以在应用中完全可以替代一些开源控件的使用。

    先说AppBarLayout这个类的使用,先看官方文档的描述:

    AppBarLayout is a vertical LinearLayout which implements many of the features of material designs app bar concept, namely scrolling gestures.

    Children should provide their desired scrolling behavior through setScrollFlags(int) and the associated layout xml attribute: app:layout_scrollFlags.

    This view depends heavily on being used as a direct child within a CoordinatorLayout. If you use AppBarLayout within a different ViewGroup, most of it’s functionality will not work.

    AppBarLayout also requires a separate scrolling sibling in order to know when to scroll. The binding is done through the AppBarLayout.ScrollingViewBehavior behavior 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.

    简单翻译一下:

    AppBarLayout是一个实现了很多材料设计特性的垂直的LinearLayout,它能响应滑动事件。必须在它的子view上设置app:layout_scrollFlags属性或者是在代码中调用setScrollFlags()设置这个属性。这个类的特性强烈依赖于它是否是一个CoordinatorLayout的直接子view,如果不是,那么它的很多特性不能够使用。AppBarLayout需要一个具有滑动属性的兄弟节点view,并且在这个兄弟节点View中指定behavior属性为AppBarLayout.ScrollingViewBehavior的类实例,可以使用一个内置的string表示这个默认的实例@string/appbar_scrolling_view_behavior.

    所有这个类的设置主要在XML布局上,一个简单的例子如下:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">
    
            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed"/>
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:gravity="center"
                android:text="hello world"/>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recylerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/appbar"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    </android.support.design.widget.CoordinatorLayout>

    我们在ToolBar中设置了app:layout_scrollFlags=”scroll|enterAlwaysCollapsed”属性,用ToolBar来响应RecyclerView的滑动。同时在RecyclerView中设置了app:layout_behavior=”@string/appbar_scrolling_view_behavior”属性,用来表明RecyclerView的滑动行为。

  • 相关阅读:
    字典--------输出有序的格式
    输出数据和数据下标的两种方法
    删除操作
    搭建RabbitMQ环境(windows)
    SpringBoot 2.x 集成 Redis
    Redis 安装
    Spring Boot 数据库操作
    默认日志Logback配置
    通过poi下载图片到word
    Spring IoC 与 AOP
  • 原文地址:https://www.cnblogs.com/summerpxy/p/13648331.html
Copyright © 2011-2022 走看看