Meterial Design常见控件的使用(五):AppbarLayout

本文详细介绍了Android中的AppBarLayout使用,包括ScrollFlag的各种效果测试,如简单滚动、快速下拉、有限度滚动等,并展示了如何根据AppBarLayout滑动位置改变视图,如TextView的位置变化和ImageView的透明度调整。同时,文章提到了在实际应用中遇到的动画响应和流畅性问题以及解决方案。
摘要由CSDN通过智能技术生成

一、AppBarLayout

AppBarLayout 是 LinearLayout 的子类,通过它,我们可以实现简单的布局滚动响应的效果。
效果是利用 behavior 完成的,不过相关代码 google 工程师都已经写好,因此我们只需要测试相关属性的效果即可。

测试前列出前提条件:

    1. AppBarLayout 父类为 CoordinatorLayout
    1. CoordinatorLayout 下有实现了 NestedScrollingChild 接口的滚动视图,例如 NestedScrollView RecyclerView,并且将 android.support.design.widget.AppBarLayout$ScrollingViewBehavior 与其绑定

二、ScrollFlag 效果测试

首先,列出 AppBarLayout 中可以使用的所有的 ScrollFlag:

//所有效果必须有 scroll 
- 1.简单滚动:scroll
- 2.快速下拉滚动:scroll | enterAlways
- 3.有限度的下拉滚动:scroll | enterAlways | enterAlwaysCollapsed
- 4.有限度的上拉滚动:scroll | exitUntilCollapsed
- 5.有弹性的滚动:scroll | snap

测试的布局文件代码:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.arno.aboutmaterialdesign.appbarlayout.AppBarLayoutActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/include_appbarlayout_toolbarId"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:layout_scrollFlags="scroll"    ------------------ 在这里更改 ScrollFlag
            app:title="Toolbar title"
            app:titleTextColor="#ffffff"
            ></android.support.v7.widget.Toolbar
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值