用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;
}
} }
 

ObjectAnimator实现菜单的弹出(扇形)的更多相关文章

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

    原文:Winform 实现像菜单一样弹出层 在实际工作中,如果能像菜单一样弹出自定义内容,会方便很多,比如查询时,比如下拉列表显示多列信息时,比如在填写某个信息需要查看一些信息树时.这个时候自定义弹出 ...

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

    用javascript实现简单的下拉折叠菜单效果 实现步骤 (a)获得各操作的dom对象: (b)在所有菜单按钮对象上添加单击事件: (c)设置所有菜单按钮样式为空,并将当前按钮的样式设置为“acti ...

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

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

  4. bootstrap 响应式导航条模板(含下拉菜单,弹出框)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 用PopupWindow实现弹出菜单(弹出的菜单采用自定义布局)

         用PopupWindow实现弹出菜单是一个比较好的方式.当然我们还有一个类PopupMenu也能实现弹出菜单,但那个太过于局限了,所以不是很推荐. 这个实例的效果是这样的:点击按钮后,一个菜 ...

  6. iOS_21团购_顶部菜单和弹出菜单联动

    最后效果图: 各控件关系图1: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize ...

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

    http://blog.csdn.net/yingtian648/article/details/52432438(转载) 1.在Toolbar.xml中设置弹出菜单的风格(app:popupThem ...

  8. ifix 在切换菜单按钮弹出”已打开该画面“bug修复

    在ifix项目中,实际上会用到点击按钮弹出按钮菜单,点击另一按钮弹出另一按钮菜单的情况.一般在使用过程中切换菜单可有如下两种普遍做法: 1.使用ClosePicture "Middle&qu ...

  9. jq 右键菜单在弹出菜单前如果需要显示与否的判断相关操作

    菜单插件(ContextMenu)接收一个额外的参数对象来设置菜单项的样式和绑定鼠标事件. 菜单插件(ContextMenu)支持一下参数设置: bindings 包含id的对象:函数组. 当关联的菜 ...

随机推荐

  1. Hdu 5052 Yaoge’s maximum profit(树链剖分)

    题目大意: 给出一棵树.每一个点有商店.每一个商店都有一个价格,Yaoge每次从x走到y都能够在一个倒卖商品,从中得取利益.当然,买一顶要在卖之前.可是没次走过一条路,这条路上的全部商品都会添加一个v ...

  2. Datatable报错Uncaught TypeError: Cannot read property 'cell' of undefined

    使用Datatables时,报出错误 仔细想想,是因为我在columns里加入了id,并设置visible:false 但是却没在下面的HTML部分多加一个 th 虽然我觉得因为id是隐藏的,不用加上 ...

  3. SharePoint2010QuickFlow安装及使用

    一:QuickFlow的安装 1,从http://quickflow.codeplex.com/下载解决方案包以及设计器. 2,将QuickFlow.dll以及QuickFlow.UI.dll添加到程 ...

  4. SVG图形的简单修改

    svg格式的图片是一种矢量图片,最近我就喜欢使用这种图片在做html的元素.网上也有很多现成的svg图片,比如:http://www.sfont.cn这个网站,就能很快的找到各种您想要的图片.但是下载 ...

  5. Objective-C 之深拷贝和浅拷贝

    3月箴言 人的思想是了不起的,只要专注于某一项事业,就一定会做出使自己感到吃惊的成绩来.—— 马克·吐温 1.iOS中关于深拷贝和浅拷贝的概念 浅拷贝:浅拷贝并不拷贝对象本身,只是对指向对象的指针进行 ...

  6. JS如何截取-后面的字符串

    str为要截取的字符串  通过获取字符串中“-”的坐标index,其他特殊字符以此类推 var index=str.lastIndexOf("\-"); str=str.subst ...

  7. TopJUI Combobox 联动

    这里给联动进行一个简单定义:因Combobox选择或输入的值发生改变时对自身或者其它组件产生影响称为联动.(注:editable确定是否可以手动输入) 有两种实现方法: 一.自己写对应的onChang ...

  8. WebSocket 客户端实例

    Node.js var ws = require("ws"); var socket = new ws("ws://127.0.0.1:8001); var socket ...

  9. Delphi在Android下通过WiFI进行调试

    如果我们需要调试USB程序且Android设备只有一个USB口,那么可以通过WiFi来调试程序,这样USB口就可以用了. 大致步骤如下: 1.在有root权限的Android设备里安装“Wifi AD ...

  10. Python3中高阶函数lambda,filter,map,reduce,zip的详细用法

    在Python里有五大高阶函数,他们分别是lambda()匿名函数,filter()筛选函数,map()函数,reduce()函数,zip()函数.下面就让我们来详细的了解一下这五种函数的具体用法吧. ...