先上效果图:

先写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. BZOJ 2288 贪心 +链表

    思路: 放个题解好吧. http://www.cnblogs.com/zyfzyf/p/4114774.html //By SiriusRen #include <queue> #incl ...

  2. python课程设计笔记(二)破冰基本语法

    python两种编程方式:交互式与文件式 交互式:语法练习,输一条运行一条 文件式:通用,执行一组语句 注释 #单行注释  ...XXXXX...多行注释 逻辑 没有大括号,按缩进确定逻辑——缩进格数 ...

  3. hdu 2489 dfs枚举组合情况+最小生成树

    大家都说,搜索是算法的基础.今天最这题就有体会了.在n个顶点里选择m个顶点,求最小生成树.用到了深搜的回溯.所有情况都能枚举. #include<iostream> #include< ...

  4. 服务器控件使用eval()绑定属性出现服务器标记的格式不正确

    在使用asp.net服务器端控件的时候,想要动态绑定控件某属性的值,或者动态绑定控件事件方法的参数,例如一个<asp:RadioButton ID="RadioButton5" ...

  5. MVC传值前台

    ViewBag.model = bLL.GetModel((int)id); ViewBag.RecruitmentTime = ViewBag.model.RecruitmentTime.ToStr ...

  6. HTML 引入 CSS、JS 的三种方式

    描述部分按 CSS 来的,其实 JavaScript 也一样,具体区别看代码 外部样式表 当样式需要被应用到很多页面的时候,外部样式表将是理想的选择.使用外部样式表,你就可以通过更改一个文件来改变整个 ...

  7. form-control给input添加这个class类后就会使用bootstrap自带的input框

    <input type="text" class="form-control" id="name" placeholder=" ...

  8. vc++实例

  9. 网站出现502 bad getway

    最近项目之余,领导叫解决下系统网站经常出现502的问题,作为小头头的我,怎能不顶上. 流程开始走起,先查nginx,嗯,配置是大众的.是不是缓存溢出了呢.调节buffer的值 .貌似也没什么影响啊.5 ...

  10. HTML5 Canvas绘制的下雪效果

    在HTML页面的HEAD区域直接引入snow.js即可,如下:<script type="text/javascript" src="js/snow.js" ...