- 浏览: 198647 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
xyyx_nk:
在demo中没有下载的示例,能详细说一下怎么监听下载过程吗?比 ...
DhNet 网络http工具(带缓存功能哦) -dhroid文档 -
zhaoguowei998:
dhroid ioc模块对 加密混淆问题 -
zhaoguowei998:
你太牛了,佩服佩服,以后要多想你请教了
dhroid ioc模块对 加密混淆问题 -
白色蜻蜓:
转载下您的文章,已注明出处。
IOS开发之百度地图API应用 -
wenjiefeng:
你好,在andrioidpn-client客户端源码里,Not ...
Android 推送之原理与初触Androidpn(Android Push Notification)
记得在eoe上有人发过,但代码质量不好。我重写了一下,抽成了控件。但没有经过各种控件的相容性测试,如果和其他控件的相容性不好,就直接在activity中写代码吧,应该差不多的。
我用的是平板,所以效果还行,不知道手机如何。
代码:
- package com.ql.view;
- import android.R.anim;
- import android.content.Context;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.RotateAnimation;
- import android.view.animation.ScaleAnimation;
- import android.view.animation.TranslateAnimation;
- import android.view.animation.Animation.AnimationListener;
- import android.widget.Button;
- import android.widget.RelativeLayout;
- import com.ql.app.R;
- public class AnimButtons extends RelativeLayout{
- private Context context;
- private int leftMargin=0,bottomMargin=0;
- private final int buttonWidth=58;//图片宽高
- private final int r=180;//半径
- private final int maxTimeSpent=200;//最长动画耗时
- private final int minTimeSpent=80;//最短动画耗时
- private int intervalTimeSpent;//每相邻2个的时间间隔
- private Button[] btns;
- private Button btn_menu;
- private RelativeLayout.LayoutParams params;
- private boolean isOpen = false;//是否菜单打开状态
- private float angle;//每个按钮之间的夹角
- public AnimButtons(Context context) {
- super(context);
- // TODO Auto-generated constructor stub
- this.context=context;
- }
- public AnimButtons(Context context, AttributeSet attrs) {
- super(context, attrs);
- // TODO Auto-generated constructor stub
- this.context=context;
- }
- @Override
- protected void onFinishInflate() {
- // TODO Auto-generated method stub
- super.onFinishInflate();
- View view=LayoutInflater.from(context).inflate(R.layout.anim_buttons, this);
- initButtons(view);
- }
- private void initButtons(View view){
- // TODO Auto-generated method stub
- //6个按钮,具体视情况而定
- btns=new Button[6];
- btns[0] = (Button) view.findViewById(R.id.btn_camera);
- btns[1] = (Button) view.findViewById(R.id.btn_with);
- btns[2] = (Button) view.findViewById(R.id.btn_place);
- btns[3] = (Button) view.findViewById(R.id.btn_music);
- btns[4] = (Button) view.findViewById(R.id.btn_thought);
- btns[5] = (Button) view.findViewById(R.id.btn_sleep);
- btn_menu = (Button) view.findViewById(R.id.btn_menu);
- leftMargin=((RelativeLayout.LayoutParams)(btn_menu.getLayoutParams())).leftMargin;
- bottomMargin=((RelativeLayout.LayoutParams)(btn_menu.getLayoutParams())).bottomMargin;
- for(int i=0;i<btns.length;i++){
- btns[i].setLayoutParams(btn_menu.getLayoutParams());//初始化的时候按钮都重合
- btns[i].setTag(String.valueOf(i));
- btns[i].setOnClickListener(clickListener);
- }
- intervalTimeSpent=(maxTimeSpent-minTimeSpent)/btns.length;//20
- angle=(float)Math.PI/(2*(btns.length-1));
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- // TODO Auto-generated method stub
- super.onSizeChanged(w, h, oldw, oldh);
- final int bottomMargins=this.getMeasuredHeight()-buttonWidth-bottomMargin;
- // Log.i("tag", "bottomMargins====="+bottomMargins);
- btn_menu.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- if(!isOpen){
- isOpen = true;
- // btn_menu.startAnimation(animRotate(-45.0f, 0.5f, 0.45f));
- for(int i=0;i<btns.length;i++){
- float xLenth=(float)(r*Math.sin(i*angle));
- float yLenth=(float)(r*Math.cos(i*angle));
- // Log.i("tag", "xLenth======"+xLenth+",yLenth======"+yLenth);
- btns[i].startAnimation(animTranslate(xLenth, -yLenth, leftMargin+(int)xLenth, bottomMargins - (int)yLenth, btns[i], minTimeSpent+i*intervalTimeSpent));
- }
- }
- else{
- isOpen = false;
- // btn_menu.startAnimation(animRotate(90.0f, 0.5f, 0.45f));
- for(int i=0;i<btns.length;i++){
- float xLenth=(float)(r*Math.sin(i*angle));
- float yLenth=(float)(r*Math.cos(i*angle));
- // Log.i("tag", "xLenth======"+xLenth+",yLenth======"+yLenth);
- btns[i].startAnimation(animTranslate(-xLenth, yLenth, leftMargin, bottomMargins, btns[i], maxTimeSpent-i*intervalTimeSpent));
- }
- }
- }
- });
- }
- private Animation animScale(float toX, float toY){
- // TODO Auto-generated method stub
- Animation animation = new ScaleAnimation(1.0f, toX, 1.0f, toY, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- animation.setInterpolator(context, anim.accelerate_decelerate_interpolator);
- animation.setDuration(400);
- animation.setFillAfter(false);
- return animation;
- }
- private Animation animRotate(float toDegrees, float pivotXValue, float pivotYValue){
- // TODO Auto-generated method stub
- final Animation animation = new RotateAnimation(0, toDegrees, Animation.RELATIVE_TO_SELF, pivotXValue, Animation.RELATIVE_TO_SELF, pivotYValue);
- animation.setAnimationListener(new AnimationListener(){
- @Override
- public void onAnimationStart(Animation animation){
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationRepeat(Animation animation){
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationEnd(Animation animation){
- // TODO Auto-generated method stub
- animation.setFillAfter(true);
- }
- });
- return animation;
- }
- private Animation animTranslate(float toX, float toY, final int lastX, final int lastY,
- final Button button, long durationMillis){
- // TODO Auto-generated method stub
- Animation animation = new TranslateAnimation(0, toX, 0, toY);
- animation.setAnimationListener(new AnimationListener(){
- @Override
- public void onAnimationStart(Animation animation){
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationRepeat(Animation animation) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationEnd(Animation animation){
- // TODO Auto-generated method stub
- params = new RelativeLayout.LayoutParams(0, 0);
- params.height = buttonWidth;
- params.width = buttonWidth;
- params.setMargins(lastX, lastY, 0, 0);
- button.setLayoutParams(params);
- button.clearAnimation();
- }
- });
- animation.setDuration(durationMillis);
- return animation;
- }
- View.OnClickListener clickListener=new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- int selectedItem=Integer.parseInt((String)v.getTag());
- for(int i=0;i<btns.length;i++){
- if(i==selectedItem){
- btns[i].startAnimation(animScale(2.0f, 2.0f));
- }else{
- btns[i].startAnimation(animScale(0.0f, 0.0f));
- }
- }
- if(onButtonClickListener!=null){
- onButtonClickListener.onButtonClick(v, selectedItem);
- }
- }
- };
- public boolean isOpen(){
- return isOpen;
- }
- private OnButtonClickListener onButtonClickListener;
- public interface OnButtonClickListener{
- void onButtonClick(View v,int id);
- }
- public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener){
- this.onButtonClickListener=onButtonClickListener;
- }
- }
布局anim_buttons.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#FFF"
- >
- <Button android:id="@+id/btn_sleep"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/composer_sleep"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- />
- <Button android:id="@+id/btn_thought"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/composer_thought"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- />
- <Button android:id="@+id/btn_music"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/composer_music"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- />
- <Button android:id="@+id/btn_place"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/composer_place"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- />
- <Button android:id="@+id/btn_with"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/composer_with"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- />
- <Button android:id="@+id/btn_camera"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/composer_camera"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- />
- <Button android:id="@+id/btn_menu"
- android:layout_width="58dip"
- android:layout_height="58dip"
- android:background="@drawable/friends_delete"
- android:layout_alignParentLeft="true"
- android:layout_alignParentBottom="true"
- android:layout_marginLeft="10dip"
- android:layout_marginBottom="10dip"
- />
- </RelativeLayout>
用法:
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- AnimButtons animButtons=(AnimButtons)findViewById(R.id.animButtons);
- animButtons.setOnButtonClickListener(new AnimButtons.OnButtonClickListener() {
- @Override
- public void onButtonClick(View v, int id) {
- // TODO Auto-generated method stub
- Log.i("tag", "id============="+id);
- }
- });
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
- <!-- layout_width,layout_height最好是fill_parent参数 -->
- <com.ql.view.AnimButtons
- android:id="@+id/animButtons"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
- </LinearLayout>
发表评论
-
Dhdb 简化sqlite数据库操作--dhroid文档
2014-04-15 12:30 1309android数据库其实使用的不多,dhroid框架中的 ... -
dhroid ioc模块对 加密混淆问题
2014-04-14 12:52 921大家应该已经看过ioc ... -
NetJSONAdapter 网络化的adapter(高效) -dhroid文档
2014-04-04 12:15 843关于adapter 我想对于大家来说已经不陌生了,基本应用 ... -
DhNet 网络http工具(带缓存功能哦) -dhroid文档
2014-03-24 13:36 1401网络请求是大多数应用不可获取的一部分,曾经和一个其他公司的 ... -
eventbus 事件总线-dhroid文档
2014-03-23 11:47 1212你听过onClick 事件,onItemClick 事件, ... -
ioc基础(视图,资源,assert注入)-dhroid文档
2014-03-21 12:59 821上一节 Android 极速开发框架 dhroid来了 ... -
ioc高级(接口,对象注入)-dhroid文档
2014-03-21 13:04 1085前一章 ioc基础( ... -
IOC容器详解(想晋升的进来)---dhroid框架教教程(一)
2014-03-20 10:30 942控制反转(Inversion of Control,英文缩写 ... -
Android 极速开发框架 dhroid来了(提供demo)
2014-03-19 17:24 1338我们公司内部使用的商业级android开发框架dhr ... -
HttpClient的3种超时说明
2013-03-14 11:05 851/* 从连接池中取连接的超时时间 */ConnManag ... -
MeasureSpec介绍及使用详解
2013-01-24 21:21 728一个MeasureSpec封装了父 ... -
Android使用自定义AlertDialog
2012-12-28 11:48 799Android使用自定义AlertDialog以下的代码是写在 ... -
Android学习——TextView 设置中划线 下划线
2012-10-31 14:42 3431android:textAppearance ... -
ListView与其中的Button,EditText,RatingBar等widget的click事件
2012-10-26 14:48 812在<RelativeLayout>中 an ... -
Android PNG渐变背景图片失真问题
2012-09-13 15:06 722最近一个困扰很久的问题,渐变效果的png图片,设置为控件 ... -
在线词典API
2012-09-09 19:34 687QQ词典 http://dict.qq.com/dic ... -
android Uri获取真实路径转换成File的方法
2012-08-23 12:40 3026data.getData()返回的 ... -
Java之WeakReference与SoftReference使用讲解
2012-08-22 09:46 648如果你想写一个 Java 程序,观察某对象什么时候会被垃圾收集 ... -
Android自定义捕获Application全局异常
2012-08-21 17:24 1146package qianlong.qlmobile ... -
android 缩放图片与内存溢出
2012-08-03 09:43 1157常用的Android版缩放图片代码: ContentRes ...
相关推荐
一款仿团购应用图片菜单效果的源码,目前已经实现了以下功能: 1.图片导航菜单展开(ExpandableListView) 2.子菜单滑动切换(ViewFlipper) 3.根据当前页面显示页标 还有两个问题,感兴趣的朋友可以研究下: 1...
https://github.com/daCapricorn/ArcMenu 博文链接:https://gundumw100.iteye.com/blog/1299953
仿Path的弹射菜单效果,可自定义弹射角度和方向,基于Android平台实现
这是一款基于js+css3制作的MacOS苹果操作系统页面底部图标菜单动画效果网页导航菜单特效。
网上开源的demo.仿path菜单,又叫卫星菜单什么的,封装好的view
本文实例讲述了JavaScript+CSS实现仿Mootools竖排弹性动画菜单效果。分享给大家供大家参考。具体如下: 这里演示JavaScript+CSS仿Mootools竖排黑色动画菜单,并非使用了Mootools,但效果却和使用了Mootools差不多,...
TabBarsAnimationDemo — 底部菜单push隐藏菜单栏动画(仿<京东> 及 <东方财富通> tabBar效果)
这是一个makovkastar的FloatingActionButton基础上的控件,主要效果是点击FAB会弹出菜单,并有动画效果.所以FAB的所有特性都能用,比如当列表滚动自动隐藏等. Screenshot 截图 Sample App download 示例App下载 ...
Android 动画(二) 实战演示——仿网易新闻安卓端菜单栏动画 博客地址:http://blog.csdn.net/u010181592/article/details/50298491
该源码是了仿QQ空间底部弹出菜单效果,效果非常类似我们现实中使用的QQ空间的底部的效果,没什么两样的了,当我们点击时,就会在底部弹出菜单,具体还是看看效果图演示图吧。
仿饿了么联动ListView,模仿饿了么点餐菜单动画,及其加入购物车抛物线动画,要想实现这个效果的自定义Item就是加了一个头部,,然后我们看效果图的时候,可以发现当第一个标题内的内容向上移动,消失的时候,那个...
仿path菜单,支持:左上;右上;右下;左下;中五个方向进行布局。利用三角函数计算位置,位置更加精准,弧度更加圆滑。中间布局时支持半圆形和圆形。
本例子是一个环形双层的菜单,可以根据手势的左右滑动,可以进行相应的转动,并且可以点击任意一个选项,动态效果类似于老式的老式的转盘电话,自己脑补一下吧。点击任何一个菜单会在logCat里面打印出当前点击项。...
仿MacOS苹果系统底部菜单代码是一款基于js css3制作的MacOS苹果操作系统页面底部图标菜单动画效果。
这是一款基于js css3制作的MacOS苹果操作系统页面底部图标菜单动画效果网页导航菜单特效。 js代码 [removed] //For the demo only setTimeout(function() { document.getElementById('downloads').class...
该六边形菜单在鼠标滑过时带有高光动画效果,当点击菜单后,各个菜单项沿六边形的各条边向外弹出,组成一个大的六边形,鼠标悬停或滑过时显示提示文字。点击中间关闭按钮又可以收起菜单。该六边形菜单使用一个svg来...
android 侧滑菜单依次弹出demo 点击菜单按钮 按顺序弹出菜单,关闭侧滑菜单也是按顺序关闭
侧滑菜单(仿qq5.0版本的侧滑效果)
仿微博、酷安点击加号揭露动画弹出菜单 背景模糊效果 截图 没有像酷安那样扩展到导航栏,以后有机会可以再研究吧。 使用的PopupWindow实现的,主要部分有 背景揭露动画;+ 旋转动画;菜单项弹出动画;背景模糊...