1. 效果图

下面是我们将要实现的效果图:

效果图

2.具体实现

我们可以利用design和v7包中的控件来实现(涉及到的控件有CoordinatorLayout、AppBarLayout、Toolbar、NestedScrollView)。

第一步:创建一个Scrolling Activity

下面是该activity的界面效果图

Scrolling Activity

第二步:编写最终效果图需要用到的xml

在第一步的基础上构造出我们最终想要的效果图。

(1) include_toolbar_open.xml

该布局是头部展开时toolbar对应的效果图:

头部展开时toolbar的效果图

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

android:layout_width="match_parent"

android:layout_height="50dp"

android:background="@color/colorPrimary"

>

android:layout_margin="@dimen/dimen_10dp"

android:layout_toLeftOf="@+id/iv_contact"

android:background="@drawable/shape_search"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/dimen_10dp"

android:paddingRight="@dimen/dimen_10dp">

android:id="@+id/iv_search"

android:layout_width="20dp"

android:layout_height="20dp"

android:layout_centerVertical="true"

android:src="@mipmap/ic_search"/>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_centerVertical="true"

android:layout_toRightOf="@id/iv_search"

android:hint="搜索商品"

android:background="@null"

android:paddingLeft="@dimen/dimen_10dp"

android:textColorHint="@android:color/white"

android:textSize="14sp"/>

android:id="@+id/iv_plus"

android:layout_width="20dp"

android:layout_height="20dp"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:layout_marginRight="@dimen/dimen_10dp"

android:src="@mipmap/ic_add"/>

android:id="@+id/iv_contact"

android:layout_width="25dp"

android:layout_height="25dp"

android:layout_centerVertical="true"

android:layout_marginRight="@dimen/dimen_10dp"

android:layout_toLeftOf="@id/iv_plus"

android:src="@mipmap/ic_contact"/>

android:id="@+id/bg_toolbar_open"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

(2) include_toolbar_close.xml

该布局是头部收缩时toolbar对应的效果图:

头部收缩时toolbar的效果图

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

android:layout_width="match_parent"

android:layout_height="50dp"

android:background="@color/colorPrimary">

android:id="@+id/iv_scan"

android:layout_width="25dp"

android:layout_height="25dp"

android:layout_alignParentLeft="true"

android:layout_centerVertical="true"

android:layout_marginLeft="20dp"

android:src="@mipmap/ic_scan"/>

android:id="@+id/iv_pay"

android:layout_width="25dp"

android:layout_height="25dp"

android:layout_centerVertical="true"

android:layout_marginLeft="20dp"

android:layout_toRightOf="@+id/iv_scan"

android:src="@mipmap/ic_payment"/>

android:id="@+id/iv_charge"

android:layout_width="25dp"

android:layout_height="25dp"

android:layout_centerVertical="true"

android:layout_marginLeft="20dp"

android:layout_toRightOf="@+id/iv_pay"

android:src="@mipmap/ic_transfer"/>

android:layout_width="25dp"

android:layout_height="25dp"

android:layout_centerVertical="true"

android:layout_marginLeft="20dp"

android:layout_toRightOf="@+id/iv_charge"

android:src="@mipmap/ic_card"/>

android:id="@+id/iv_plus"

android:layout_width="25dp"

android:layout_height="25dp"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:layout_marginRight="20dp"

android:layout_toRightOf="@+id/iv_scan"

android:src="@mipmap/ic_add"/>

android:id="@+id/bg_toolbar_close"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

(3) include_open.xml

该布局是头部打开时折叠区对应的效果图:

头部打开时折叠区对应的效果图

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/colorPrimary">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="match_parent"

android:gravity="center"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@mipmap/ic_scan"/>

android:layout_gravity="center_horizontal"

android:layout_marginTop="5dp"

android:text="扫一扫"

android:textColor="@color/white"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="match_parent"

android:gravity="center"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@mipmap/ic_payment"/>

android:layout_gravity="center_horizontal"

android:layout_marginTop="5dp"

android:text="付钱"

android:textColor="@color/white"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="match_parent"

android:gravity="center"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@mipmap/ic_transfer"/>

android:layout_gravity="center_horizontal"

android:layout_marginTop="5dp"

android:text="收钱"

android:textColor="@color/white"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="match_parent"

android:gravity="center"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@mipmap/ic_card"/>

android:layout_gravity="center_horizontal"

android:layout_marginTop="5dp"

android:text="卡包"

android:textColor="@color/white"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:id="@+id/bg_content"

android:layout_width="match_parent"

android:layout_height="100dp"/>

(3) content_zfbhome_telescopic.xml

内容区

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"

app:layout_behavior="@string/appbar_scrolling_view_behavior"

tools:context=".activity.ZFBHomeTelescopicActivity"

tools:showIn="@layout/activity_zfbhome_telescopic">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="@dimen/text_margin"

android:text="@string/large_text" />

(3) activity_zfbhome_telescopic.xml

最终的在activity布局里的效果图:

最终效果图

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"

android:fitsSystemWindows="true"

tools:context=".activity.ZFBHomeTelescopicActivity">

android:id="@+id/app_bar"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/toolbar_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:contentScrim="?attr/colorPrimary"

app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"

>

layout="@layout/include_open"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="50dp"

app:layout_collapseMode="parallax"

app:layout_collapseParallaxMultiplier="0.7"/>

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="50dp"

app:contentInsetLeft="0dp"

app:contentInsetStart="0dp"

app:layout_collapseMode="pin" >

layout="@layout/include_toolbar_open"/>

layout="@layout/include_toolbar_close"/>

注:布局中涉及到的一些属性具体的作用就不做阐述了,可以自行查阅。

第三步:主Activity(ZFBHomeTelescopicActivity.java)

我们需要对AppBarLayout设置偏移监听,需要实现一些背景色缩放效果和收缩展开时toolbar对应布局的显示。

public class ZFBHomeTelescopicActivity extends AppCompatActivity implements AppBarLayout.OnOffsetChangedListener {

@BindView(R.id.bg_content)

View bgContent; //大布局背景遮罩层

@BindView(R.id.iv_search)

ImageView ivSearch; //

@BindView(R.id.iv_plus)

ImageView ivPlus;

@BindView(R.id.iv_contact)

ImageView ivContact;

@BindView(R.id.iv_scan)

ImageView ivScan;

@BindView(R.id.iv_pay)

ImageView ivPay;

@BindView(R.id.iv_charge)

ImageView ivCharge;

@BindView(R.id.bg_toolbar_close)

View bgToolbarClose; //收缩状态下toolbar的遮罩层

@BindView(R.id.toolbar)

Toolbar toolbar;

@BindView(R.id.toolbar_layout)

CollapsingToolbarLayout toolbarLayout;

@BindView(R.id.app_bar)

AppBarLayout appBar;

@BindView(R.id.bg_toolbar_open) //展开状态下toolbar的遮罩层

View bgToolbarOpen;

private View toolbarOpen; //展开状态下toolbar显示的内容

private View toolbarClose; //收缩状态下toolbar显示的内容

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_zfbhome_telescopic);

ButterKnife.bind(this);

toolbarOpen = findViewById(R.id.include_toolbar_open);

toolbarClose = findViewById(R.id.include_toolbar_close);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

appBar.addOnOffsetChangedListener(this);

}

@Override

public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {

//垂直方向偏移

int offset = Math.abs(verticalOffset);

//最大偏移距离

int scrollRange = appBarLayout.getTotalScrollRange();

//当滑动没超过一半时,展开状态下toolbar显示内容,根据收缩位置,改变透明值

if (offset <= scrollRange / 2){

toolbarOpen.setVisibility(View.VISIBLE);

toolbarClose.setVisibility(View.GONE);

//根据偏移百分比,计算透明值

float scale2 = (float) offset / (scrollRange / 2);

int alpha2 = (int) (255 * scale2);

bgToolbarOpen.setBackgroundColor(Color.argb(alpha2,25,131,209));

}else {//当滑动超过一半,收缩状态下toolbar显示内容,根据收缩位置,改变透明值

toolbarClose.setVisibility(View.VISIBLE);

toolbarOpen.setVisibility(View.GONE);

float scale3 = (float) (scrollRange - offset) / (scrollRange / 2);

int alpha3 = (int) (255 * scale3);

bgToolbarClose.setBackgroundColor(Color.argb(alpha3,25,131,209));

}

//根据偏移值百分比计算扫一扫布局的透明度值

float scale = (float) offset / scrollRange;

int alpha = (int) (255 * scale);

bgContent.setBackgroundColor(Color.argb(alpha,25,131,209));

}

@Override

protected void onDestroy() {

super.onDestroy();

appBar.removeOnOffsetChangedListener(this);

}

}

Android仿支付宝UI功能开发,UI实例--仿支付宝首页头部伸缩效果相关推荐

  1. Android P适配以太网功能开发指南

            Android P适配以太网功能开发指南 Android网络框架分析系列文章目录: Android P适配以太网功能开发指南 Android以太网框架情景分析之启动简介 Android ...

  2. 支付宝支付功能实现原理,微信公众号中实现支付宝支付功能开发流程

    这篇文章使用一些简单的代码例子来解释微信接入支付宝支付功能的操作步骤,即使新手也可以轻松参透的. 第三方支付是指具备一定实力和信誉保障的独立机构,采用与各大银行签约的方式,通过与银行支付结算系统接口对 ...

  3. 非常详细 !!!支付宝支付功能开发配置Demo演示

    1.搜索支付宝开放平台,使用支付宝扫码即可登录 2.配置沙箱环境***,找到开发服务–>研发服务,点击进入后即可开始配置 3.点击沙箱应用可以看到如下图所示,APPID是支付宝根据个人登录的支付 ...

  4. android 微博字体高亮,安卓开发札记——高仿新浪微博文字处理(实现关键字高亮,自定义表情替换并加入点击事件实现)...

    安卓开发笔记--高仿新浪微博文字处理(实现关键字高亮,自定义表情替换并加入点击事件实现) 先让大家看下效果图,这个是我自己在闲暇时间仿写的新浪微博客户端: 今天来讲讲如何实现上图的效果,这里需要用到S ...

  5. android 画板之橡皮擦功能开发

    记录一下橡皮擦功能开发. 讲一下原理: 橡皮擦功能要用到Paint类的一个属性: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DS ...

  6. java支付宝对账功能开发_java后台实现支付宝对账功能

    完成支付宝支付.查询的接口之后,我们应该还需要定时与支付宝进行对账,以确保商户系统的订单信息是正确的,想知道支付宝支付.查询接口实现过程的亲们,可移步到上一篇有详细过程. 现在我们来讲一下支付宝对账的 ...

  7. java支付宝提现功能,单笔转账到支付宝账户(公钥证书方式)

    最近在开发商户分润系统(给商户分红),涉及到给商户账号提现功能,我们使用的是支付宝转账,通过公钥证书方式实现的. 在支付宝开放平台里找了好久的开发文档,但是介绍更多的是普通公钥的方式,这个方式比较简单 ...

  8. Android仿支付宝UI功能开发,Android 自定义view仿支付宝咻一咻功能

    支付宝上有一个咻一咻的功能,就是点击图片后四周有水波纹的这种效果,今天也写一个类似的功能. 效果如下所示: 思路: 就是几个圆的半径不断在变大,这个可以使用动画缩放实现,还有透明动画 还有就是这是好几 ...

  9. Android仿支付宝UI功能开发,Android类似支付宝我的界面切片

    Android界面制作-类似支付宝我的界面,内含整个项目.效果图 内含以下栏目: 头像.姓名 账单.总资产.余额. 银行卡.保险服务.公益等 资源下载: 视频地址(优酷):http://v.youku ...

最新文章

  1. hadoop HDFS常用文件操作命令
  2. 阿里感悟(十三)降低成本的敏捷设计
  3. 又一年度热销爆款,OPPO R11上市一个月勇夺线下销量第一
  4. kmeans图像分割
  5. Docker+Jenkins+Nginx+Spring Boot 自动化部署项目
  6. 【网址收藏】Spark History Server配置及使用
  7. SQL SERVER中一些常见性能问题的总结
  8. 创建订单 - 扣除商品库存与订单状态保存
  9. 学习笔记(30):Python网络编程并发编程-Event事件
  10. 剑指offer之找到链表里面包含环的入口节点
  11. oracle bcp out,SQL Server利用bcp命令把SQL语句结果生成文本文件
  12. window系统服务器改名,微软:不会将 Windows Server 改名为 Microsoft Server 系统
  13. 心心念特斯拉Cybertruck?现在可以下单了,订金1000块
  14. loading窗口动画 web_loading动画
  15. newton版本linux,centos7.4下安装部署openstack newton版本 互联网技术圈 互联网技术圈...
  16. python web 文件管理器_利用Python 1分钟搭建测试Web服务器,可实现linux目录文件共享...
  17. 骑行日志2011滇藏珠峰尼泊尔青藏 - 记那些逝去的青春
  18. Heaven of Imaginary(PKUSC2018)
  19. Zeppelin解释器的REST API接口
  20. Android计步器算法实现(2)

热门文章

  1. W3Cshool中的mysql命令说明及用法。转载自W3school
  2. 2.说明计算机环境下会计循环的八个流程,2020年云南自考《会计信息系统》要点复习(二)...
  3. 克鲁斯卡尔重构树及简单应用
  4. uvm中sequence和virtual sequence中objection的控制
  5. funkyheatmap | 用这个包来完美复刻Nature Biotechnology的高颜值神图吧!~
  6. 《深度强化学习》面试题汇总
  7. 云展网教程 | 如何把云展的杂志下载下来上传到自己的网站(服务空间)?
  8. 全媒社:媒体报道宣传和渠道选择有密切关联
  9. 复试21天Day 17
  10. 机器人机构学基础(朱大昌)第四章部分习题答案