先上效果图:

先写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. android 学习记录-----------android 活动 意图 碎片

    将此篇博客作为记录android项目开发过程中的学习记录

  2. NOIP2012 D2 T2 借教室 线段树 OR 二分法

    题目描述: 在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海量租借教室的信息,我们自 ...

  3. POJ 2406 KMP next数组的应用

    题意:让你找最小重复串的个数 加深KMP中对next数组的理解 #include <cstdio> #include <cstring> using namespace std ...

  4. showdialog

    在C#中窗口的显示有两种方式:模态显示(showdialog)和非模态显示(show). 区别: 模态与非模态窗体的主要区别是窗体显示的时候是否可以操作其他窗体.模态窗体不允许操作其他窗体,非模态窗体 ...

  5. Walking on the path of Redis --- Introduction and Installation

    废话开篇 以前从来没听说过有Redis这么个玩意,无意间看到一位仁兄的博客,才对其有所了解,所以决定对其深入了解下.有不对的地方还请各位指正. Redis介绍 下面是官方的介绍,不喜欢english的 ...

  6. logging模块、shutil模块、subprocess模块、xml模块

    logging模块 shutil模块 subprocess模块 xml模块 logging模块 函数式简单配置 import logging logging.debug('debug message' ...

  7. SpringMVC源码阅读

    在研究SpringMVC工作流程的同时记录下过程,以便以后浏览. 版本号:5.0.4 前沿:我们在使用SpringMVC的时候会在web.xml中配置以下servlet <!-- 配置sprin ...

  8. Oracle语句执行顺序

  9. Python笔记16-------类

    1.类的定义 (1)#括号中要加入父类,如果没有则默认为object,万类之源 class 类名(父类): '类的文档字符串' 类体代码 若类什么都不做,则类只作为命名空间,仅作为一个容器. (2)类 ...

  10. Mysql错误:#1054 - Unknown column '字段名' in 'field list'

    # 1054 - Unknown column '字段名' in 'field list' 第一个就是你的表中没有这个字段 另一个就是你的这个字段前后可能有空格!!!,去掉空格即可!