Android学习笔记(八)--CoordinatorLayout的应用-仿支付宝界面

本文介绍了如何使用CoordinatorLayout实现类似支付宝界面的上滑收缩和变化功能。核心在于利用CoordinatorLayout作为顶层布局协调子视图交互,通过Behavior进行定制。文中详细讲解了布局设计、关键代码实现,包括AppBarLayout的OnOffsetChangedListener监听偏移量变化来调整视图状态,并提供了完整代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

哈哈,差不多有一个礼拜没有更新,去广东那边旅游了四五天所以就没有更新,接下来就要恢复正常了,又要开始学习了。今天带来的是关于CoordinatorLayout的应用,模仿着支付宝做了一个界面,先看一下效果图吧。
这里写图片描述
实现了和支付宝一样的上滑收缩和变化的功能。核心使用的就是今天要说的coordinatorLayout。CoordinatorLayout作为“super-powered FrameLayout”基本实现两个功能:
1、作为顶层布局
2、调度协调子布局
就我的大白话来说就是协调子View之间动作的一个父View,通过Behavior来给子view实现交互的。
另外使用CoordinatorLayout需要在Gradle加入Support Design Library

compile 'com.android.support:design:24.2.1'

然后先看一下主布局。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.sp.coordinatortry.MainActivity">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/color1984D1"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            app:title=" ">
            <include layout="@layout/shenghuo_head1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="100dp"
                android:layout_marginBottom="25dp"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.8"/>
            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:contentInsetLeft=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值