当前位置:我的异常网» Web前端 » 三分钟带你仿携程飞机票首页炫酷交互

三分钟带你仿携程飞机票首页炫酷交互

www.myexceptions.net  网友分享于:2013-12-23  浏览:0次

三分钟带你仿携程机票首页炫酷交互

这些效果熟悉MD的同学肯定一下就能够想到三大利器:CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout。往这个方面想就对了,今天我们就要用这三个东西来搞一个炫酷的交互效果。先简单看一下这三大利器。

CoordinatorLayout

Design包下的控件,作用如其名字是用来协调操作控件的布局,可以通过自定义Behavior来协调和控制子View之间的交互。

AppBarLayout

继承自LinearLayout,在竖直方向的LinearLayout基础上增加了一些Material Design的设计概念,同样可以定义滑动时子View的交互方式。

CollapsingToolbarLayout

为Toolbar而生的控件,用来操控Toolbar实现一些炫酷的折叠效果,可以为Toolbar和StatusBar在滑动阀值时添加scrim效果以及控制Toolbar等其他子View滑动的视差滚动(parallax)

老规矩,先上布局文件:

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/coordinatorLayout"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/app_bar"

android:layout_width="match_parent"

android:layout_height="160dp"

android:fitsSystemWindows="true"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

android:id="@+id/toolbar_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:contentScrim="@android:color/transparent"

app:statusBarScrim="@android:color/transparent"

app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

android:id="@+id/banner"

android:layout_width="match_parent"

android:layout_height="160dp"

app:autoPlayDuration="5000"

app:indicatorMargin="50dp"

app:indicatorPosition="centerBottom"

app:indicatorShape="oval"

app:indicatorSpace="3dp"

app:scrollDuration="1100"

app:defaultImage="@mipmap/ic_launcher"

app:selectedIndicatorColor="?attr/colorPrimary"

app:selectedIndicatorHeight="6dp"

app:selectedIndicatorWidth="6dp"

app:unSelectedIndicatorColor="#99ffffff"

app:unSelectedIndicatorHeight="6dp"

app:unSelectedIndicatorWidth="6dp"

app:layout_collapseMode="parallax"

app:layout_collapseParallaxMultiplier="0.7"/>

android:id="@+id/view"

android:layout_width="match_parent"

android:layout_height="40dp"

android:background="@drawable/gradient" />

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:minHeight="?attr/actionBarSize"

android:gravity="top"

app:layout_collapseMode="pin"/>

android:id="@+id/search_tab_container"

android:layout_width="match_parent"

android:layout_height="43dp"

android:layout_marginBottom="-4dp"

android:layout_gravity="bottom">

android:layout_width="match_parent"

android:layout_height="40dp"

android:background="#5a000000"

android:layout_marginLeft="5dp"

android:layout_marginTop="3dp"

android:layout_marginBottom="-4dp"

android:layout_marginRight="5dp"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="bottom"

android:layout_marginBottom="-4dp"

android:layout_marginLeft="5dp"

android:layout_marginRight="5dp"

android:orientation="horizontal">

android:id="@+id/slide_bg"

android:layout_width="120dp"

android:layout_height="43dp"

android:background="@drawable/ctrip_slide_tab"/>

android:id="@+id/rg_slide"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:gravity="center"

android:layout_centerInParent="true">

android:id="@+id/rb_left"

android:background="@null"

android:textColor="@color/top_layout_sliide_text_color_selector"

android:gravity="center"

android:button="@null"

android:textSize="16dp"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:checked="false"

android:text="单程" />

android:id="@+id/rb_center"

android:background="@null"

android:textColor="@color/top_layout_sliide_text_color_selector"

android:gravity="center"

android:textSize="16dp"

android:button="@null"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="往返" />

android:id="@+id/rb_right"

android:background="@null"

android:button="@null"

android:textColor="@color/top_layout_sliide_text_color_selector"

android:gravity="center"

android:textSize="16dp"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:singleLine="true"

android:text="多程"

android:visibility="visible" />

android:id="@+id/top_container"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:minHeight="?attr/actionBarSize"

android:orientation="horizontal"

android:gravity="center"

android:layout_gravity="top"

app:layout_collapseMode="pin"

android:background="@color/ctirp_color_primary">

android:layout_width="261dp"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:gravity="center"

android:layout_centerInParent="true">

android:background="@drawable/title_left_shape"

android:padding="6dp"

android:textColor="@color/top_layout_text_color_selector"

android:gravity="center"

android:button="@null"

android:textSize="16dp"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:checked="true"

android:text="单程" />

android:background="@drawable/title_center_shape"

android:padding="6dp"

android:textColor="@color/top_layout_text_color_selector"

android:gravity="center"

android:textSize="16dp"

android:button="@null"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:layout_marginLeft="-1dp"

android:layout_marginRight="-1dp"

android:text="往返" />

android:background="@drawable/title_right_shape"

android:padding="6dp"

android:button="@null"

android:textColor="@color/top_layout_text_color_selector"

android:gravity="center"

android:textSize="16dp"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:singleLine="true"

android:text="多程"

android:visibility="visible" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:src="@drawable/search_bg"

android:scaleType="fitStart"/>

当然,除了布局文件,我们在Activity里也要对一些情况进行特殊处理才能完成携程的效果.

首先,我们布局里的广告轮播用了com.yyydjk.library.BannerLayout,github上的开源项目,图片是去携程App上抓出来的。

除此之外,还需要去监听我们整体的滑动过程,通过滑动的位置来为一些控件设置Alpha值从而达到渐变隐藏和显示的效果,这里采用的是为AppBarLayout提供OnOffsetChangedListener监听,这样就可以得到竖直方向的offset

mAppBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

@Override

public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {

mSlideView.setAlpha(getAlpha(verticalOffset, appBarLayout.getTotalScrollRange()));

mTop.setAlpha(1.0f - getAlpha(verticalOffset, appBarLayout.getTotalScrollRange()));

}

});

}

就酱,整个仿写的过程就完成了,赶紧编译试试吧,效果还是挺好的。

交流群103791667

文章评论

php仿携程网站,三分钟带你仿携程飞机票首页炫酷交互相关推荐

  1. 三分钟带你读懂 BERT

    本文为 AI 研习社编译的技术博客,原标题 : BERT Technology introduced in 3-minutes 作者 | Suleiman Khan, Ph.D. 翻译 | 胡瑛皓.s ...

  2. 建网站的最简单方法(三分钟带后台)

    建网站的最简单方法(三分钟带后台) 准备材料 服务器或者本地环境 安装过程 准备材料 织梦二次开发模板或者Ecshop二次开发模板等(我以织梦为例讲解) 如果是本地需要下载ComsenzEXP或者Wa ...

  3. mysql和oracle冲突吗_三分钟带你分清MySQL 和Oracle之间的误区

    原标题:三分钟带你分清MySQL 和Oracle之间的误区 来自:华为云开发者社区 摘要:MySQL和Oracle,别再傻傻分不清. MySQL 和Oracle 在开发中的使用是随处可见的,那就简单去 ...

  4. 三分钟带你看懂prototype原型——ES6进阶

    三分钟带你看懂prototype原型--ES6进阶 1. prototype 定义 2. new 构造函数 3. 存储 4. prototype 作用 1. prototype 定义 在JS中的类的实 ...

  5. 三分钟带你弄懂slot插槽——vue进阶

    文章目录 三分钟带你弄懂slot插槽--vue进阶 一.概述 程序员之死 什么是 slot插槽? 2.6.0 版本中的 slot 二.具名插槽 例子 效果图 代码 三.小惊喜 三分钟带你弄懂slot插 ...

  6. 三分钟带你看懂HDMI接口的PCB设计

    三分钟带你看懂HDMI接口的PCB设计 本文主要讲解的是HDMI的设计,包括作用和运用的总结,希望大家看了以后能轻松的应对各种HDMI方案的PCB设计. 一.什么是HDMI? 高清晰度多媒体接口(英文 ...

  7. 网站首页炫酷动态背景实现

    网站首页炫酷动态背景实现 先贴出我苦找良久的网站动态背景图 实现过程 先来一个html简单的显示界面 <!doctype html> <html><head>< ...

  8. 三分钟带你了解不一样的场效应管

    目前市场上的场效应管主要分为两种,但不论是哪种,场效应管都具有功耗低噪声小,而且不会出现二次击穿的特点,这让其成为替代晶体管的最佳产品.随着场效应管应用面积的扩大,对场效应管的选择和检查也成为了设计者 ...

  9. 三分钟带您搞懂代理模式

    全文共1439字,预计阅读时间:10分钟 定义: 代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问. 代理模式是一种比较贴近于生活的 设计模式,现实生活中也有很多代理模式的例子: ...

  10. 三分钟带你弄懂GFS(Google File System)

    提示:预计阅读时间三分钟,该文章仅对GFS做了一的简略介绍,细节方面建议阅读原文. 文章目录 前言 一.GFS是什么? 1.1 简单介绍 1.2 我们为什么需要阅读GFS的论文? 1.3 GFS论文对 ...

最新文章

  1. 最牛逼的性能监控系统!集强大功能于一身
  2. Python程序设计题解【蓝桥杯官网题库】 DAY13-算法训练
  3. OpenInventor开发笔记:解决FaceSet的填充问题
  4. 【放置奇兵】封印之地各阵营boss和小怪属性
  5. Python的DEBUG LOG
  6. Structs2 ModelDriven使用方法介绍
  7. python安装pyecharts清华_基于Python安装pyecharts所遇的问题及解决方法
  8. 计算机综合应用能力试题,计算机综合应用能力实训
  9. 使用nginx简单实现负载均衡
  10. 【BZOJ3684】大朋友和多叉树(拉格朗日反演)
  11. NFS环境搭建测试 保证挂载重启后不丢失
  12. linux学习笔记(11)df命令
  13. FI-MM-CO T-CODE (中英文)
  14. 航天信息上传参数设置服务器设置,金税盘上传参数怎么设置?
  15. 广义预测控制及其matlab仿真,广义预测控制(GPC).doc
  16. 为语音社交平台加一个防护罩,即构上线实时语音安全方案
  17. mysql存储表情字符_MySQL 存储表情字符
  18. [linux] linux sed命令删除一行/多行
  19. Postman接口测试教程_Sinno_Song_新浪博客
  20. 超详细!一篇文章带你轻松入门神经调控

热门文章

  1. Java版本微信授权登录(概览版)
  2. Android垂直方向滚动的跑马灯,带gif
  3. 计算机rs485通讯,RS485与电脑通信
  4. keil中c语言定义数组,如题,KeilC51位变量能不能定义数组
  5. Apache的管理优化
  6. vnc远程控制软件,五款良心推荐的vnc远程控制软件
  7. 复变函数总结一:复变函数
  8. 【文学杂谈】徐宥 - 我的大学
  9. 搜狗浏览器显示无法解析服务器的DNS,Win10专业版下搜狗浏览器DNS解析失败
  10. 浏览器错误信息无法解析服务器,win10系统使用搜狗浏览器提示无法解析服务器的dns地址的修复教程...