先上效果图:

先写Layout文件:

<?xml version="1.0" encoding="utf-8"?

>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"> <ImageView
android:id="@+id/sat_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sat_main"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
/> <ImageView
android:id="@+id/sat_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/> <ImageView
android:id="@+id/clone_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/> </RelativeLayout>

这3个ImageView都在屏幕的底部,clone_item须要固定在球弹起的最高位置:

初始化这3个imageView:

  sat_main = (ImageView)findViewById(R.id.sat_main);
final ImageView itemView = (ImageView)findViewById(R.id.sat_item);
final ImageView cloneView = (ImageView)findViewById(R.id.clone_item);
cloneView.setImageResource(R.drawable.searchable_web);
itemView.setImageResource(R.drawable.searchable_web);
itemView.setVisibility(View.GONE);

初始化cloneView的位置:

//这个是使cloneview固定在leftmargin x bottomMargin y的地方
RelativeLayout.LayoutParams layoutParams =(RelativeLayout.LayoutParams) cloneView.getLayoutParams();
layoutParams.bottomMargin = Math.abs(y);
layoutParams.leftMargin = Math.abs(x);
cloneView.setLayoutParams(layoutParams);

点击button时候。button本身会旋转:

<?

xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="-135"
android:pivotX="50%"
android:pivotY="50%"
android:duration="300"
android:fillAfter="true"
android:fillEnabled="true"/>

用下面方法得到球的终于位置:x坐标是distance*cos(角度),y是distance*sin(角度)

	//取得distance的cos(degree)
public static int getTranslateX(float degree, int distance) {
return Double.valueOf(distance * Math.cos(Math.toRadians(degree))).intValue();
} public static int getTranslateY(float degree, int distance){
return Double.valueOf(-1 * distance * Math.sin(Math.toRadians(degree))).intValue();
}

然后球弹起的动画:

	public static Animation createItemOutAnimation(Context context, int index, long expandDuration, int x, int y){

        AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
long alphaDuration = 60;
if(expandDuration < 60){
alphaDuration = expandDuration / 4;
}
alphaAnimation.setDuration(alphaDuration);
alphaAnimation.setStartOffset(0); //x和y是球弹到最高点的坐标
TranslateAnimation translate = new TranslateAnimation(0, x, 0, y); translate.setStartOffset(0);
translate.setDuration(expandDuration);
//OvershootInterpolator:表示向前甩一定值后再回到原来位置。 translate.setInterpolator(context, R.anim.sat_item_overshoot_interpolator); RotateAnimation rotate = new RotateAnimation(0f, 360f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f); //AccelerateInterpolator:动画从開始到结束。变化率是一个加速的过程。
//DecelerateInterpolator:动画从開始到结束。变化率是一个减速的过程
rotate.setInterpolator(context, R.anim.sat_item_out_rotate_interpolator); long duration = 100;
if(expandDuration <= 150){
duration = expandDuration / 3;
} rotate.setDuration(expandDuration-duration);
rotate.setStartOffset(duration); AnimationSet animationSet = new AnimationSet(false);
animationSet.setFillAfter(false);
animationSet.setFillBefore(true);
animationSet.setFillEnabled(true); animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(rotate);
animationSet.addAnimation(translate); animationSet.setStartOffset(30*index); return animationSet;
}

这个动画弹到最高点后,我们得使itemview gone掉。cloneview visible

代码的位置:http://download.csdn.net/detail/baidu_nod/7722621

android一个弹出菜单的动画(一)的更多相关文章

  1. android一个弹出菜单的动画(二)

    假设做一个弹出的控件,我们能够进行加入view: 写class SatelliteMenu extends FrameLayout private void init(Context context, ...

  2. 获得其他程序弹出菜单的内容(一个困扰许久的问题o(╯□╰)o)

    刚开始到现在公司的时候接到一个任务:开发一个activex控件,自动操作本地exe程序,当时遇到弹出菜单无法获取的问题,还好不影响,最近又遇到这个问题,绕不过去了,于是昨天花了一个上午百度了个遍,总算 ...

  3. IOS实现弹出菜单效果MenuViewController(背景 景深 弹出菜单)

    在写项目时,要实现一个从下移上来的一个弹出菜单,并且背景变深的这么一个效果,在此分享给大家. 主要说一下思路及一些核心代码贴出来,要想下载源码, 请到:http://download.csdn.net ...

  4. win32进阶之路:程序托盘图标+右键弹出菜单

     开场白 本次介绍两个非常棒且实用的技巧:程序托盘图标和右键弹出菜单,效果如下图. 程序托盘图标用了迅雷的图标,右键点击时候会弹出三个选项的菜单. 程序托盘图标设置 我会用尽可能清晰明了的步骤介绍方式 ...

  5. Mui --- 弹出菜单

    mui框架内置了弹出菜单插件,弹出菜单显示内容不限,但必须包裹在一个含.mui-popover类的div中,如下即为一个弹出菜单内容: <div id="popover" c ...

  6. [译]GLUT教程 - 弹出菜单基础

    Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Popup Menus 弹出菜单也是GLUT的一部分.虽然 ...

  7. 关于MFC主菜单和右键弹出菜单

    一.主菜单.弹出菜单和右键菜单的概念: 主菜单是窗口顶部的菜单,一个窗口或对话框只能有一个主菜单,但是主菜单可以被更改(SetMenu()更改): 创建方式:CMenu::CreateMenu(voi ...

  8. 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单

    前一篇文章中有用到 PopupWindow 来实现弹窗的功能.简单介绍以下吧. 官方文档是这样解释的:这就是一个弹出窗口,可以用来显示一个任意视图.出现的弹出窗口是一个浮动容器的当前活动. 1.首先来 ...

  9. 【转】 教你如何创建类似QQ的android弹出菜单

    原文地址:http://www.apkbus.com/android-18034-1-1.html 大家可能看到android的自带的系统菜单比较难看,如图: 2011-12-4 23:13 上传 下 ...

随机推荐

  1. .NET微服务架构及API网关

    一.MSA简介 1.1.MSA是什么 微服务架构MSA是Microservice Architecture的简称,它是一种架构模式,它提倡将单一应用程序划分成一组小的服务,服务之间互相通讯.互相配合, ...

  2. WinForm导出DataSet到Excel

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. [原创]Java常见笔试题知识点汇总

    前天数梦工厂来学校招聘,笔试题比较有特点,全是Java题,基本就是Java的一些特点.凭记忆按照题目找到一些必备知识点 (1). try {}里有一个return语句,那么紧跟在这个try后的fina ...

  4. c++ 编译期与运行期

    分享到 一键分享 QQ空间 新浪微博 百度云收藏 人人网 腾讯微博 百度相册 开心网 腾讯朋友 百度贴吧 豆瓣网 搜狐微博 百度新首页 QQ好友 和讯微博 更多... 百度分享 转自:http://h ...

  5. H5 微信公众号 监听返回事件

    /*-----监听返回事件-----*/ function pushHistory(returnUrl,currentUrl,currentTitle) { window.addEventListen ...

  6. 从ReadImage到ML- 一个不错的博客

    实在对不起原作者,为了不把文章淹没在 转载的海洋里.... 原文链接:     http://www.cnblogs.com/tornadomeet/archive/2012/09/26/270404 ...

  7. javaee 文件的复制

    package Shurushucu; import java.io.FileInputStream; import java.io.FileNotFoundException; import jav ...

  8. vim利器:vundle 管理器和NERDTree插件

    vundle 和nerdtree vundle git: https://github.com/VundleVim/Vundle.vim.git nerdtree git : https://gith ...

  9. python类的内置attr属性

    class Foo: x=1 def __init__(self,y): self.y=y def __getattr__(self, item): print('----> from geta ...

  10. Bind for 0.0.0.0:80 failed: port is already allocated.解决方案

    一句话总结就是容器占用的port还没有完全释放 查看进程,发现相关的容器并没有在运行,而 docker-proxy 却依然绑定着端口: $ docker ps 检查docker镜像 $ ps -aux ...