用ObjectAnimator 实现菜单的弹出

首先是菜单的图片资源和布局

布局中使用FrameLaout 将菜单唤出对应的imageView放在布局的最后面来隐藏菜单详细内容。

<?xml version="1.0" encoding="utf-8"?><FrameLayout 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=".MainActivity">

    <ImageView        android:id="@+id/imageView_b"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:layout_gravity="bottom|right"        android:src="@drawable/b"/>    <ImageView        android:id="@+id/imageView_c"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:layout_gravity="bottom|right"        android:src="@drawable/c"/>    <ImageView        android:id="@+id/imageView_d"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:layout_gravity="bottom|right"        android:src="@drawable/d"/>    <ImageView        android:id="@+id/imageView_e"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:layout_gravity="bottom|right"        android:src="@drawable/e"/>    <ImageView        android:id="@+id/imageView_f"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:layout_gravity="bottom|right"        android:src="@drawable/f"/>

    <ImageView        android:id="@+id/imageView_g"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:layout_gravity="bottom|right"        android:src="@drawable/g" />    <ImageView        android:id="@+id/imageView_a"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:layout_gravity="bottom|right"        android:src="@drawable/a"/>

</FrameLayout>

package com.a18470.mooc_animtest;

import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.animation.BounceInterpolator;import android.widget.ImageView;import android.widget.Toast;

import java.util.ArrayList;import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{    private int[] res = {R.id.imageView_a, R.id.imageView_b, R.id.imageView_c,            R.id.imageView_d, R.id.imageView_e, R.id.imageView_f, R.id.imageView_g};    private List<ImageView> imageViewList = new ArrayList<ImageView>();    private boolean flag = false;    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        for(int i=0;i<res.length;i++){            ImageView imageView = findViewById(res[i]);            imageView.setOnClickListener(this);            imageViewList.add(imageView);        }    }

    @Override    public void onClick(View v) {        switch (v.getId()){            case R.id.imageView_a:                for (int i = 1; i < res.length; i++) {                    ImageView menu = imageViewList.get(i);                    double angle = Math.toRadians(i * (90 * 1.0 / (res.length - 1))); // 角度                    double radius = 450; // 半径                    float distanceX = (float) (Math.cos(angle) * radius); // X坐标偏移量                    float distanceY = (float) (Math.sin(angle) * radius); // Y坐标偏移量                    ObjectAnimator animatorX;                    ObjectAnimator animatorY;                    if (flag) { // 如果菜单是打开的则关闭菜单                        animatorX = ObjectAnimator.ofFloat(menu, "translationX", -distanceX, 0f);                        animatorY = ObjectAnimator.ofFloat(menu, "translationY", -distanceY, 0f);                    } else { // 如果菜单是关闭的则打开菜单                        animatorX = ObjectAnimator.ofFloat(menu, "translationX", 0f, -distanceX);                        animatorY = ObjectAnimator.ofFloat(menu, "translationY", 0f, -distanceY);                    }                    AnimatorSet set = new AnimatorSet(); // X、Y轴同时移动                    set.playTogether(animatorX, animatorY);                    set.setDuration(500);                    set.setInterpolator(new BounceInterpolator());                    set.start();                }                flag = !flag;                break;            default:                Toast.makeText(MainActivity.this,"click"+v.getId(),Toast.LENGTH_SHORT).show();                break;        }    }

}
 

转载于:https://www.cnblogs.com/kongbb/p/10538150.html

ObjectAnimator实现菜单的弹出(扇形)相关推荐

  1. html下拉折叠菜单,原生Js_实现简单的下拉折叠菜单(添加弹出动画效果)

    用javascript实现简单的下拉折叠菜单 Gary_js实现简单的下拉折叠菜单 *{margin:0px; padding:0px;} #div1 {width:200px; margin:0 a ...

  2. python 提示框如何顶层显示_python tkinter之顶层菜单、弹出菜单实例

    我就废话不多说了,直接看代码吧! from tkinter import * def sys_callbak(): pass def fun_callbak(): pass def no_thing( ...

  3. Bootstrap—解决下拉菜单不弹出问题

    最近学到Bootstrap下拉菜单,学懂了教程内容之后自己敲一个点击按钮底下弹出下拉菜单的小demo,写完代码发现运行之后点击按钮没反应,下拉菜单弹不出来,对照教程感觉代码没错. 我的代码如下: &l ...

  4. Android的Toolbar(含溢出菜单设置[弹出菜单的使用])的使用PopMenu的样式

    工作内容: Toolbar(含溢出菜单设置[弹出菜单的使用])的使用 学习分享: Toolbar的使用前提:设置主题 <style name="AppTheme" paren ...

  5. python tkinter 下拉框_python中tkinter入门之Menu创建顶级菜单、下拉菜单和弹出菜单。...

    创建顶级菜单 Menu 组件通常被用于实现应用程序上的各种菜单.使用add_command可以添加菜单内容.创建后通过root.config()添加到窗口上. from tkinter import ...

  6. php tinyme_黄聪:TinyMCE 4 增强 添加样式、按钮、字体、下拉菜单和弹出式窗口

    我最喜欢 WordPress 3.9 的更新是使用了 TinyMCE 4.0 编辑器.新的 TinyMCE 看起来看起来更整洁(真正匹配WP仪表板),它有一些非常不错的附加功能.我的很多老主题和插件必 ...

  7. Winform 实现像菜单一样弹出层

    在实际工作中,如果能像菜单一样弹出自定义内容,会方便很多,比如查询时,比如下拉列表显示多列信息时,比如在填写某个信息需要查看一些信息树时.这个时候自定义弹出界面就显的非常重要了 我这里其实用到的是网上 ...

  8. 【Java中的菜单的常用方法】下拉菜单和弹出菜单

    目录 Swing菜单组件 下拉式菜单 下拉式菜单的三个组件的详细讲解 下拉式菜单的创建与使用 创建和添加下拉式菜单的一般步骤 弹出式菜单 弹出式菜单的创建与使用 Swing菜单组件 下拉式菜单 创建一 ...

  9. 035-JAVA语言实现下拉菜单与弹出菜单功能

    上一章:034-用Swing组件综合应用(实现QQ登录与注册界面功能)_CSDN专家-赖老师(软件之家)的博客-CSDN博客 下一讲:036-JList列表控件使用案例讲解_CSDN专家-赖老师(软件 ...

  10. java点击菜单项文字显示在窗体上_java点击菜单项弹出窗口怎么做啊?

    程序如下,可弹不出窗口呀,高手教教我!importjava.awt.*;importjava.awt.event.*;publicclassW111extendsFrameimplementsActi ...

最新文章

  1. centos ezhttp mysql_CentOS安装mysq
  2. 百度地图-解决新版百度定位失败问题
  3. es6在原生代码的用法_关于ES6的模块化
  4. notepad++ linux 打开二进制文件
  5. htc资料和js和css的嵌套
  6. 史无前例的 HTML5 资源参考指南
  7. getopt和getopt_long函数
  8. DXUT框架剖析系列文章(原创:天行健 君子当自强而不息)
  9. Java 从入门到精通 第16章String类
  10. 【指纹识别】基于matlab GUI指纹预处理+特征点提取【含Matlab源码 1693期】
  11. 绿盟科技 linux漏洞,apache漏洞修复(绿盟科技漏洞)
  12. 【卫朋】硬件创业:营销与开发同行
  13. matlab 直方图(柱状图) 及 CDF曲线
  14. dtools: error while loading shared libraries: libicui18n.so.55: cannot open shared object file
  15. 游戏行业如何上云?阿里云架构师解读四大主流游戏架构
  16. CVPR 2022 部分行人重识别
  17. 2048游戏代码java总结_软件工程——Java版2048游戏学习报告
  18. try 和 catch 用法
  19. 一唯,ev录屏过程中断电视频的恢复,视频恢复修复
  20. 《Pytorch 模型推理及多任务通用范式》_第3节课

热门文章

  1. 12个新鲜出炉的Web开发框架
  2. BitPlots包简介
  3. GGally与pairs相关关系图_史上最全(一)
  4. 什么是生命,这取决于肝脏。——《调音师》影评
  5. Kafka监控系统Kafka Eagle:支持kerberos认证
  6. Angular Taskmgr 登录
  7. ACM_一道耗时间的水题
  8. 【bzoj1093】[ZJOI2007]最大半连通子图 Tarjan+拓扑排序+dp
  9. es5 和 es6 class
  10. 【图论】[BZOJ 1051]受欢迎的牛