- 浏览: 518746 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
tangyunliang:
大哥你太历害了谢谢
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
u013015029:
LZ,请问下,在// 添加消息到聊天窗口 , 这里获取Ed ...
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
endual:
怎么保持会话,我搞不懂啊
Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器 -
donala_zq:
显示:[2013-11-30 11:50:36 - Andro ...
android-----------新浪微博 -
donala_zq:
哥,运行不了啊
android-----------新浪微博
点击前效果:
[img]
[/img]
点击后效果:
[img]
[/img]
/res/layout/main :
res/layout/anim_buttons :
MainActivity:
AnimButtons:
本文转自:http://gundumw100.iteye.com/blog/1299953
[img]
[/img]
点击后效果:
[img]
[/img]
/res/layout/main :
<?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" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <com.magus.button.AnimButtons android:id="@+id/animButtons" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
res/layout/anim_buttons :
<?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>
MainActivity:
package com.magus.button; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override 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); } }); } }
AnimButtons:
package com.magus.button; 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; 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() { 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; } }
本文转自:http://gundumw100.iteye.com/blog/1299953
发表评论
-
Android中如何模拟一次点击(touch)事件
2014-05-06 10:41 0在Android中有时需要模拟某一个View的touch事件, ... -
Android程序Crash时的异常上报
2014-04-28 18:15 0http://blog.csdn.net/singwhatiw ... -
android程序中证书签名校验的方法
2014-04-28 17:58 1909android程序中证书签名校验的方法一 2013-02 ... -
MD5理解错了,哎
2014-03-17 14:14 0MD5只对数据加密是无法解密的,也就是说,你把100加密后,就 ... -
Android 获取网络时间
2014-03-12 11:42 2015Android 获取网络时间 在网上看到的最常见的方式有: ... -
SQLite清空表并将自增列归零
2014-03-05 18:02 1476SQLite清空表并将自增列归零 作者:Zhu Yanfeng ... -
Handler小看一下
2013-11-11 16:42 0android handler调用post方法还是阻塞 su ... -
Frame Animation小看一下
2013-10-12 16:30 724Demo运行效果图: 源码: -
动画小学一下
2013-10-12 16:14 697转自: http://www.eoeandroid.com/f ... -
Android 动画之ScaleAnimation应用详解
2013-10-12 15:49 967===============eoeAndroid社区推荐:= ... -
android开发中的一个工具类
2013-06-19 16:04 0package com.wanpu.login.dialog; ... -
android TextView怎么设置个别字体颜色并换行?
2013-06-20 09:25 1643(1)、TextView 设置个别字体颜色 TextView ... -
Android开发之文件下载,状态时显示下载进度,点击自动安装
2013-05-07 15:38 1374在进行软件升级时,需要进行文件下载,在这里实现自定义的文件下载 ... -
android中的状态保存
2013-04-07 14:21 938package com.zzl.call; import ... -
android动画基础:tween动画
2013-04-06 11:21 1184工程结构图: [img] [/img] 四个动画的xml ... -
面试中遇到的几个问题
2013-06-09 11:56 949SAX与DOM之间的区别 SAX ( ... -
Android获取其他包的Context实例,然后调用它的方法,反射!!!
2013-03-25 10:32 1164Android中有Context的概念,想必大家都知道。Con ... -
Android的内存机制和常见泄漏情形
2013-03-06 16:55 760一、 Android的内存机制 Android的程序由Ja ... -
JUnit测试小小demo
2013-03-06 16:37 1093运行效果图: [img] [/img] 项目结构图 ... -
android开发中的异常小工具
2013-03-04 15:53 866package com.zzl.tools; impor ...
相关推荐
一款仿团购应用图片菜单效果的源码,目前已经实现了以下功能: 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
仿饿了么联动ListView,模仿饿了么点餐菜单动画,及其加入购物车抛物线动画,要想实现这个效果的自定义Item就是加了一个头部,,然后我们看效果图的时候,可以发现当第一个标题内的内容向上移动,消失的时候,那个...
仿path菜单,支持:左上;右上;右下;左下;中五个方向进行布局。利用三角函数计算位置,位置更加精准,弧度更加圆滑。中间布局时支持半圆形和圆形。
该源码是了仿QQ空间底部弹出菜单效果,效果非常类似我们现实中使用的QQ空间的底部的效果,没什么两样的了,当我们点击时,就会在底部弹出菜单,具体还是看看效果图演示图吧。
仿MacOS苹果系统底部菜单代码是一款基于js css3制作的MacOS苹果操作系统页面底部图标菜单动画效果。
这是一款基于js css3制作的MacOS苹果操作系统页面底部图标菜单动画效果网页导航菜单特效。 js代码 [removed] //For the demo only setTimeout(function() { document.getElementById('downloads').class...
android 侧滑菜单依次弹出demo 点击菜单按钮 按顺序弹出菜单,关闭侧滑菜单也是按顺序关闭
侧滑菜单(仿qq5.0版本的侧滑效果)
仿微博、酷安点击加号揭露动画弹出菜单 背景模糊效果 截图 没有像酷安那样扩展到导航栏,以后有机会可以再研究吧。 使用的PopupWindow实现的,主要部分有 背景揭露动画;+ 旋转动画;菜单项弹出动画;背景模糊...
这是一款仿stripe.com网站的带变形动画特效的下拉导航菜单特效。该导航菜单在菜单项之间切换时,下拉菜单会根据菜单内容的大小来动态变形,效果非常有趣。