android一个弹出菜单的动画(一)
先上效果图:
先写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
android一个弹出菜单的动画(一)的更多相关文章
- android一个弹出菜单的动画(二)
假设做一个弹出的控件,我们能够进行加入view: 写class SatelliteMenu extends FrameLayout private void init(Context context, ...
- 获得其他程序弹出菜单的内容(一个困扰许久的问题o(╯□╰)o)
刚开始到现在公司的时候接到一个任务:开发一个activex控件,自动操作本地exe程序,当时遇到弹出菜单无法获取的问题,还好不影响,最近又遇到这个问题,绕不过去了,于是昨天花了一个上午百度了个遍,总算 ...
- IOS实现弹出菜单效果MenuViewController(背景 景深 弹出菜单)
在写项目时,要实现一个从下移上来的一个弹出菜单,并且背景变深的这么一个效果,在此分享给大家. 主要说一下思路及一些核心代码贴出来,要想下载源码, 请到:http://download.csdn.net ...
- win32进阶之路:程序托盘图标+右键弹出菜单
开场白 本次介绍两个非常棒且实用的技巧:程序托盘图标和右键弹出菜单,效果如下图. 程序托盘图标用了迅雷的图标,右键点击时候会弹出三个选项的菜单. 程序托盘图标设置 我会用尽可能清晰明了的步骤介绍方式 ...
- Mui --- 弹出菜单
mui框架内置了弹出菜单插件,弹出菜单显示内容不限,但必须包裹在一个含.mui-popover类的div中,如下即为一个弹出菜单内容: <div id="popover" c ...
- [译]GLUT教程 - 弹出菜单基础
Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Popup Menus 弹出菜单也是GLUT的一部分.虽然 ...
- 关于MFC主菜单和右键弹出菜单
一.主菜单.弹出菜单和右键菜单的概念: 主菜单是窗口顶部的菜单,一个窗口或对话框只能有一个主菜单,但是主菜单可以被更改(SetMenu()更改): 创建方式:CMenu::CreateMenu(voi ...
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
前一篇文章中有用到 PopupWindow 来实现弹窗的功能.简单介绍以下吧. 官方文档是这样解释的:这就是一个弹出窗口,可以用来显示一个任意视图.出现的弹出窗口是一个浮动容器的当前活动. 1.首先来 ...
- 【转】 教你如何创建类似QQ的android弹出菜单
原文地址:http://www.apkbus.com/android-18034-1-1.html 大家可能看到android的自带的系统菜单比较难看,如图: 2011-12-4 23:13 上传 下 ...
随机推荐
- 第18章 Redis数据结构常用命令
18-1 字符串的一些基本命令 18-1 :配置Spring关于Redis字符串的运行环境 <bean id="poolConfig" class="redis.c ...
- virtualbox 安装虚拟机(centos7) 并映射本地文件夹至虚拟机(增强工具)
一.安装环境 操作系统:windows10 virtualbox: 5.2.20 (在安装virtualbox 时可能需要 进入BIOS 设置虚拟化系统启动) centos7:http://mirro ...
- postgresql 备份(pg_dump,pg_restore)
PG提供物理备份和逻辑备份(本篇主要讲逻辑备份)物理备份:WAL热备份逻辑备份:pg_dump,pg_dumpall,恢复时pg_restore 查看帮助命令: pg_dump --help 跟MyS ...
- Endnote导入共享数据
Endnote导入共享数据 Endnote是我们经常使用的参考文献管理工具.但是,在云计算还不是很普及的今天,往往每台电脑上都有自己的endnote数据库.这样,换了电脑,要使用同样的参考文献数据时, ...
- python ansible api
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : test2.py # @Author: Anthony.waa # @Date : 20 ...
- 织梦dedecms红黑配图片模板源码v2.0
dedecms红黑配风格美女图片站是采用dedecms程序搭建的图片网站源码,网站感觉很大气,简约但是不简单,适合做图片网站.网站模板是收集其他网站的模板,感谢原网站提供者.在安装过程中出现问题,现已 ...
- MySQL 5.6 Reference Manual-14.3 InnoDB Transaction Model and Locking
14.3 InnoDB Transaction Model and Locking 14.3.1 InnoDB Lock Modes 14.3.2 InnoDB Record, Gap, and Ne ...
- 【Oracle】删除undo表空间时,表空间被占用:ORA-30042: Cannot offline the undo tablespace
特别注意:此办法只用于实在没有办法的时候,因为需要加入oracle中的隐含参数,慎用!!! 1. 先查一下是什么在占用undo SYS@ENMOEDU>select segment_name,o ...
- UWP Tiles
1.我们建议安装通知库 NuGet 程序包 详细内容 2.我们建议安装NotificationsVisualizerLibrary 这是 The official NotificationsVisua ...
- ajax发送请求是图标转圈圈实现
css部分 .load-img{ //控制图标大小width:40px;height:40px;margin:100px;border-radius:50%;-webkit-animation:cir ...