浮动按钮的弹出菜单动画

将几个按钮重叠摆放,使用ValueAnimator更新按钮的坐标实现。

布局

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"> <android.support.design.widget.FloatingActionButton
android:id="@+id/float_btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="20dp"
android:layout_marginEnd="10dp"
android:src="@mipmap/fav_2"
app:elevation="5dp"
app:fabSize="normal" /> <android.support.design.widget.FloatingActionButton
android:id="@+id/float_btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="20dp"
android:layout_marginEnd="10dp"
android:src="@mipmap/idea"
app:elevation="5dp"
app:fabSize="normal" /> <android.support.design.widget.FloatingActionButton
android:id="@+id/float_btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="20dp"
android:layout_marginEnd="10dp"
android:src="@mipmap/faxian"
app:elevation="5dp"
app:fabSize="normal" /> <android.support.design.widget.FloatingActionButton
android:id="@+id/float_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="20dp"
android:layout_marginEnd="10dp"
android:src="@mipmap/menu"
app:elevation="5dp"
app:fabSize="normal" /> </FrameLayout>

控制

private FloatingActionButton actionButton, actionButton1, actionButton2, actionButton3;
private boolean menuOpen = false;
private void showMenu() {
menuOpen = true;
int x = (int) actionButton.getX();
int y = (int) actionButton.getY();
ValueAnimator v1 = ValueAnimator.ofInt(x, x - DISTANCE);
v1.setDuration(500);
v1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int l = (int) animation.getAnimatedValue();
int t = (int) actionButton1.getY();
int r = actionButton1.getWidth() + l;
int b = actionButton1.getHeight() + t;
actionButton1.layout(l, t, r, b);
}
});
ValueAnimator v2x = ValueAnimator.ofInt(x, x - DISTANCE2);
ValueAnimator v2y = ValueAnimator.ofInt(y, y - DISTANCE2);
v2x.setDuration(500).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int l = (int) animation.getAnimatedValue();
int t = (int) actionButton2.getY();
int r = actionButton2.getWidth() + l;
int b = actionButton2.getHeight() + t;
actionButton2.layout(l, t, r, b);
}
});
v2y.setDuration(500).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int t = (int) animation.getAnimatedValue();
int l = (int) actionButton2.getX();
int r = actionButton2.getWidth() + l;
int b = actionButton2.getHeight() + t;
actionButton2.layout(l, t, r, b);
}
});
ValueAnimator v3 = ValueAnimator.ofInt(y, y - DISTANCE);
v3.setDuration(500).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int t = (int) animation.getAnimatedValue();
int l = (int) actionButton3.getX();
int r = actionButton3.getWidth() + l;
int b = actionButton3.getHeight() + t;
actionButton3.layout(l, t, r, b);
}
});
v1.start();
v2x.start();
v2y.start();
v3.start();
} private void hideMenu() {
menuOpen = false;
int x = (int) actionButton1.getX();
ValueAnimator v1 = ValueAnimator.ofInt(x, (int) actionButton.getX());
v1.setDuration(500);
v1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int l = (int) animation.getAnimatedValue();
int t = (int) actionButton1.getY();
int r = actionButton1.getWidth() + l;
int b = actionButton1.getHeight() + t;
actionButton1.layout(l, t, r, b);
}
});
x = (int) actionButton2.getX();
int y = (int) actionButton2.getY();
ValueAnimator v2x = ValueAnimator.ofInt(x, (int) actionButton.getX());
ValueAnimator v2y = ValueAnimator.ofInt(y, (int) actionButton.getY());
v2x.setDuration(500).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int l = (int) animation.getAnimatedValue();
int t = (int) actionButton2.getY();
int r = actionButton2.getWidth() + l;
int b = actionButton2.getHeight() + t;
actionButton2.layout(l, t, r, b);
}
});
v2y.setDuration(500).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int t = (int) animation.getAnimatedValue();
int l = (int) actionButton2.getX();
int r = actionButton2.getWidth() + l;
int b = actionButton2.getHeight() + t;
actionButton2.layout(l, t, r, b);
}
});
y = (int) actionButton3.getY();
ValueAnimator v3 = ValueAnimator.ofInt(y, (int) actionButton.getY());
v3.setDuration(500).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int t = (int) animation.getAnimatedValue();
int l = (int) actionButton3.getX();
int r = actionButton3.getWidth() + l;
int b = actionButton3.getHeight() + t;
actionButton3.layout(l, t, r, b);
}
});
v1.start();
v2x.start();
v2y.start();
v3.start();
}

FloatActionButton弹出菜单的更多相关文章

  1. 向上弹出菜单jQuery插件

    插件名:柯乐义英文名:Keleyijs文件名称:jquery.keleyi.js插件功能:该插件可以让你轻易地在页面上构建一个向上弹出的二级菜单. 示例查看:http://keleyi.com/kel ...

  2. html5手机端遮罩弹出菜单代码

    效果体验:http://hovertree.com/texiao/html5/17/ 效果图: 代码如下: <!doctype html> <html lang="zh&q ...

  3. DIV+CSS制作二级横向弹出菜单,略简单

    没有使用JavaScript控制二级菜单的显示,结果如上图所示. 代码如下: <!DOCTYPE html> <html> <head> <meta char ...

  4. vc++ 如何添加右键弹出菜单

    一.创建新工程 二.编辑菜单资源 1.添加菜单 按"Ctrl+R",双击"Menu"图标 2.于菜单编辑器内编辑菜单 四.添加代码(红色部分) void CCM ...

  5. 创建 iPhone/iOS8 弹出菜单(窗口)

    基本步骤 添加视图:主视图与弹出视图 关联视图 配置弹出视图 编码实现:弹出菜单样式及控制器委托 override func prepareForSegue(segue: UIStoryboardSe ...

  6. android 单选、多选弹出菜单

    菜单单选窗口: import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInte ...

  7. [Flex] PopUpButton系列 —— 弹出菜单的行高设置

    <?xml version="1.0" encoding="utf-8"?> <!--Flex中如何通过variableRowHeight样式 ...

  8. [Flex] PopUpButton系列 —— 控制弹出菜单的透明度、可用、可选择状态

    <?xml version="1.0" encoding="utf-8"?><!--控制弹出菜单的透明度.可用.可选择状态 PopUpButt ...

  9. [Flex] PopUpButton系列 —— 设置弹出菜单与主按钮之间的间隔

    <?xml version="1.0" encoding="utf-8"?><!--设置弹出菜单与主按钮之间的间隔 PopUpButtonPo ...

随机推荐

  1. spring cloud(二) zuul

    spring cloud 网关 zuul 搭建过程 1. 新建boot工程 pom引入依赖 <dependency> <groupId>org.springframework. ...

  2. [luogu3237 HNOI2014] 米特运输 (树形dp)

    传送门 Description 米特是D星球上一种非常神秘的物质,蕴含着巨大的能量.在以米特为主要能源的D星上,这种米特能源的运输和储存一直是一个大问题. D星上有N个城市,我们将其顺序编号为1到N, ...

  3. [luogu P2590 ZJOI2008] 树的统计 (树链剖分)

    题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u ...

  4. Python复利

    Python复利 复利的计算是对本金及其产生的利息一并计算,也就是利上有利. 复利计算的特点是:把上期末的本利和作为下一期的本金,在计算时每一期本金的数额是不同的.复利的计算公式是:   s = 0 ...

  5. Spring学习总结(17)——Spring AOP权限管理

    每个项目都会有权限管理系统 无论你是一个简单的企业站,还是一个复杂到爆的平台级项目,都会涉及到用户登录.权限管理这些必不可少的业务逻辑.有人说,企业站需要什么权限管理阿?那行吧,你那可能叫静态页面,就 ...

  6. MySQL 存储

    1.存储过程简介 我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户 ...

  7. cogs 306. [SGOI] 糊涂的记者

    306. [SGOI] 糊涂的记者 ★★★   输入文件:sign.in   输出文件:sign.out   评测插件时间限制:1 s   内存限制:128 MB [问题描述] 在如今的信息社会中,时 ...

  8. 页面安装Jre

    <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height ...

  9. [Beginning SharePoint Designer 2010]Chapter2 编辑页面

    本章概要: 1.如何展开隐藏任务面板和ribbon标签 2.页面编辑模式 3.代码视图模式和智能提示 4.如何组合SharePoint和页面上其他元素

  10. POJ 1944

    明天补上... 这道题的思路确实很精致.考虑到连的边肯定不会是一个环,所以至少有一个断点.于是,可以枚举这个断点.断点一确定,那么连边的走向也就确定了.用D[i]表示由i开始可以到达的最远点即可.对于 ...