ObjectAnimator实现菜单的弹出(扇形)
用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实现菜单的弹出(扇形)的更多相关文章
- Winform 实现像菜单一样弹出层
原文:Winform 实现像菜单一样弹出层 在实际工作中,如果能像菜单一样弹出自定义内容,会方便很多,比如查询时,比如下拉列表显示多列信息时,比如在填写某个信息需要查看一些信息树时.这个时候自定义弹出 ...
- 原生Js_实现简单的下拉折叠菜单(添加弹出动画效果)
用javascript实现简单的下拉折叠菜单效果 实现步骤 (a)获得各操作的dom对象: (b)在所有菜单按钮对象上添加单击事件: (c)设置所有菜单按钮样式为空,并将当前按钮的样式设置为“acti ...
- 黄聪:TinyMCE 4 增强 添加样式、按钮、字体、下拉菜单和弹出式窗口
我最喜欢 WordPress 3.9 的更新是使用了 TinyMCE 4.0 编辑器.新的 TinyMCE 看起来看起来更整洁(真正匹配WP仪表板),它有一些非常不错的附加功能.我的很多老主题和插件必 ...
- bootstrap 响应式导航条模板(含下拉菜单,弹出框)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 用PopupWindow实现弹出菜单(弹出的菜单采用自定义布局)
用PopupWindow实现弹出菜单是一个比较好的方式.当然我们还有一个类PopupMenu也能实现弹出菜单,但那个太过于局限了,所以不是很推荐. 这个实例的效果是这样的:点击按钮后,一个菜 ...
- iOS_21团购_顶部菜单和弹出菜单联动
最后效果图: 各控件关系图1: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize ...
- Android的Toolbar(含溢出菜单设置[弹出菜单的使用])的使用PopMenu的样式
http://blog.csdn.net/yingtian648/article/details/52432438(转载) 1.在Toolbar.xml中设置弹出菜单的风格(app:popupThem ...
- ifix 在切换菜单按钮弹出”已打开该画面“bug修复
在ifix项目中,实际上会用到点击按钮弹出按钮菜单,点击另一按钮弹出另一按钮菜单的情况.一般在使用过程中切换菜单可有如下两种普遍做法: 1.使用ClosePicture "Middle&qu ...
- jq 右键菜单在弹出菜单前如果需要显示与否的判断相关操作
菜单插件(ContextMenu)接收一个额外的参数对象来设置菜单项的样式和绑定鼠标事件. 菜单插件(ContextMenu)支持一下参数设置: bindings 包含id的对象:函数组. 当关联的菜 ...
随机推荐
- Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task
With the copy task of Gradle we can copy files that are parsed by Groovy's SimpleTemplateEngine. Thi ...
- linux文件系统写过程简析
linux写入磁盘过程经历VFS -> 页缓存(page cache) -> 具体的文件系统(ext2/3/4.XFS.ReiserFS等) -> Block IO ->设备 ...
- Linux内存管理-高端内存(一)
高端内存是指物理地址大于 896M 的内存.对于这样的内存,无法在“内核直接映射空间”进行映射. 为什么? 因为“内核直接映射空间”最多只能从 3G 到 4G,只能直接映射 1G 物理内存,对于大于 ...
- 【星云测试】开发者测试-采用精准测试工具对Spring Boot应用进行测试
简介:本文主要介绍把现今主流的springboot框架项目和精准测试工具进行结合和应用,通过精准测试的数据穿透.数据采集.测试用例与代码的双向追溯.数据分析等一系列精准测试的特有功能,达到对项目质量的 ...
- CORS跨域实现思路及相关解决方案
本篇包括以下内容: CORS 定义 CORS 对比 JSONP CORS,BROWSER支持情况 主要用途 Ajax请求跨域资源的异常 CORS 实现思路 安全说明 CORS 几种解决方案 自定义CO ...
- 在正文部分操作accordion内容展开和闭合
$('#accordionid').accordion("select",0); //展开第一个title $('#accordionid').accord ...
- select2 多选 排序(版本3.4.6)
使用select2多选,页面选择值的顺序与传到control的值的顺序不一致,为了方便,没有改变本来js文件,在页面上面通过change方法改变. 1.页面代码(添加修改使用同一个页面) <li ...
- TensorFlow的前世和今生
TensorFlow的前世和今生 TensorFlow是一个开放源码的软件库,用于跨一系列任务的数据流处理编程.TensorFlow是一个符号化的数学应用库,广泛用于机器学习,例如神经网络.在谷歌公司 ...
- Tomcat 或JBOSS java.lang.ArrayIndexOutOfBoundsException: 8192原因及其解决方法
2018-04-02 09:24:55 org.apache.catalina.connector.CoyoteAdapter service 严重: An exception or error oc ...
- IOT大数据大世界大未来,物联网产业大数据应用简析
在物联网时代,面对PB级的数据,企业将难以以一己之力完成基础设施的建设.物联网所产生的大量数据不仅会驱动现在的数据中心发生根本性的变化,同时也会驱动相关企业采用新的大数据策略. 物联网的价值在于数据: ...