仿path菜单button的实现「建议收藏」

仿path菜单button的实现

大家好,又见面了,我是全栈君。

path刚出来时。其菜单button也算是让大多数人感到了惊艳,如今看来事实上是非常easy的就是动画的结合。

仿path菜单button的实现「建议收藏」仿path菜单button的实现「建议收藏」

基本的代码类 

package cn.com.karl.anim;

import com.zdp.aseo.content.AseoZdpAseo;

import android.R.anim;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
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.LayoutParams;
import android.widget.TextView;

public class PathButtonActivity extends Activity 
{
	private Button buttonCamera, buttonDelete, buttonWith, buttonPlace, buttonMusic, buttonThought, buttonSleep;
	private Animation animationTranslate, animationRotate, animationScale;
	private static int width, height;
	private LayoutParams params = new LayoutParams(0, 0);
	private static Boolean isClick = false;
	private TextView refresh;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.path_button);
        
       
        initialButton();
  
        
    }
	private void initialButton() 
	{
		// TODO Auto-generated method stub
		Display display = getWindowManager().getDefaultDisplay(); 
		height = display.getHeight();  
		width = display.getWidth();
		Log.v("width  & height is:", String.valueOf(width) + ", " + String.valueOf(height));
		
		params.height = 50;
		params.width = 50;
		//设置边距  (int left, int top, int right, int bottom)
		params.setMargins(10, height - 98, 0, 0);
		
		buttonSleep = (Button) findViewById(R.id.button_composer_sleep);	
		buttonSleep.setLayoutParams(params);
		
		buttonThought = (Button) findViewById(R.id.button_composer_thought);
		buttonThought.setLayoutParams(params);
		
		buttonMusic = (Button) findViewById(R.id.button_composer_music);
		buttonMusic.setLayoutParams(params);
		
		buttonPlace = (Button) findViewById(R.id.button_composer_place);
		buttonPlace.setLayoutParams(params);
		
		buttonWith = (Button) findViewById(R.id.button_composer_with);
		buttonWith.setLayoutParams(params);

		buttonCamera = (Button) findViewById(R.id.button_composer_camera);
		buttonCamera.setLayoutParams(params);
		
		buttonDelete = (Button) findViewById(R.id.button_friends_delete);		
		buttonDelete.setLayoutParams(params);
		
		buttonDelete.setOnClickListener(new OnClickListener() 
		{
				
			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub					
				if(isClick == false)
				{
					isClick = true;
					buttonDelete.startAnimation(animRotate(-45.0f, 0.5f, 0.45f));					
					buttonCamera.startAnimation(animTranslate(0.0f, -180.0f, 10, height - 240, buttonCamera, 80));
					buttonWith.startAnimation(animTranslate(30.0f, -150.0f, 60, height - 230, buttonWith, 100));
					buttonPlace.startAnimation(animTranslate(70.0f, -120.0f, 110, height - 210, buttonPlace, 120));
					buttonMusic.startAnimation(animTranslate(80.0f, -110.0f, 150, height - 180, buttonMusic, 140));
					buttonThought.startAnimation(animTranslate(90.0f, -60.0f, 175, height - 135, buttonThought, 160));
					buttonSleep.startAnimation(animTranslate(170.0f, -30.0f, 190, height - 90, buttonSleep, 180));
				
				}
				else
				{					
					isClick = false;
					buttonDelete.startAnimation(animRotate(90.0f, 0.5f, 0.45f));
					buttonCamera.startAnimation(animTranslate(0.0f, 140.0f, 10, height - 98, buttonCamera, 180));
					buttonWith.startAnimation(animTranslate(-50.0f, 130.0f, 10, height - 98, buttonWith, 160));
					buttonPlace.startAnimation(animTranslate(-100.0f, 110.0f, 10, height - 98, buttonPlace, 140));
					buttonMusic.startAnimation(animTranslate(-140.0f, 80.0f, 10, height - 98, buttonMusic, 120));
					buttonThought.startAnimation(animTranslate(-160.0f, 40.0f, 10, height - 98, buttonThought, 80));
					buttonSleep.startAnimation(animTranslate(-170.0f, 0.0f, 10, height - 98, buttonSleep, 50));
					
				}
					
			}
		});
		buttonCamera.setOnClickListener(new OnClickListener() 
		{
				
			@Override
			public void onClick(View v) 
			{
				// TODO 自身放大 其余按钮缩小  
				buttonCamera.startAnimation(setAnimScale(2.5f, 2.5f));
				buttonWith.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonPlace.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonMusic.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonThought.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonSleep.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonDelete.startAnimation(setAnimScale(0.0f, 0.0f));
			}
		});
		buttonWith.setOnClickListener(new OnClickListener() 
		{
				
			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub					
				buttonWith.startAnimation(setAnimScale(2.5f, 2.5f));	
				buttonCamera.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonPlace.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonMusic.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonThought.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonSleep.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonDelete.startAnimation(setAnimScale(0.0f, 0.0f));
			}
		});
		buttonPlace.setOnClickListener(new OnClickListener() 
		{
				
			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub					
				buttonPlace.startAnimation(setAnimScale(2.5f, 2.5f));
				buttonWith.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonCamera.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonMusic.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonThought.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonSleep.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonDelete.startAnimation(setAnimScale(0.0f, 0.0f));
			}
		});
		buttonMusic.setOnClickListener(new OnClickListener() 
		{
				
			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub					
				buttonMusic.startAnimation(setAnimScale(2.5f, 2.5f));
				buttonPlace.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonWith.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonCamera.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonThought.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonSleep.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonDelete.startAnimation(setAnimScale(0.0f, 0.0f));
			}
		});
		buttonThought.setOnClickListener(new OnClickListener() 
		{
				
			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub					
				buttonThought.startAnimation(setAnimScale(2.5f, 2.5f));
				buttonPlace.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonWith.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonCamera.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonMusic.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonSleep.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonDelete.startAnimation(setAnimScale(0.0f, 0.0f));
			}
		});
		buttonSleep.setOnClickListener(new OnClickListener() 
		{
				
			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub					
				buttonSleep.startAnimation(setAnimScale(2.5f, 2.5f));
				buttonPlace.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonWith.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonCamera.startAnimation(setAnimScale(0.0f, 0.0f));	
				buttonMusic.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonThought.startAnimation(setAnimScale(0.0f, 0.0f));
				buttonDelete.startAnimation(setAnimScale(0.0f, 0.0f));
			}
		});
		
	}
	
	protected Animation setAnimScale(float toX, float toY) 
	{
		// TODO Auto-generated method stub
		animationScale = new ScaleAnimation(1f, toX, 1f, toY, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.45f);
		animationScale.setInterpolator(PathButtonActivity.this, anim.accelerate_decelerate_interpolator);
		animationScale.setDuration(500);
		animationScale.setFillAfter(false);
		return animationScale;
		
	}
	
	protected Animation animRotate(float toDegrees, float pivotXValue, float pivotYValue) 
	{
		// TODO Auto-generated method stub
		animationRotate = new RotateAnimation(0, toDegrees, Animation.RELATIVE_TO_SELF, pivotXValue, Animation.RELATIVE_TO_SELF, pivotYValue);
		animationRotate.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
				animationRotate.setFillAfter(true);
			}
		});
		return animationRotate;
	}
	//移动的动画效果        
	/* 
	 * TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 
	 * 
	 * float fromXDelta:这个參数表示动画開始的点离当前View X坐标上的差值。
     *
         * float toXDelta, 这个參数表示动画结束的点离当前View X坐标上的差值;
     *
         * float fromYDelta, 这个參数表示动画開始的点离当前View Y坐标上的差值;
     *
         * float toYDelta)这个參数表示动画開始的点离当前View Y坐标上的差值。
	 */
	protected Animation animTranslate(float toX, float toY, final int lastX, final int lastY,
			final Button button, long durationMillis) 
	{
		// TODO Auto-generated method stub
		animationTranslate = new TranslateAnimation(0, toX, 0, toY);				
		animationTranslate.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 LayoutParams(0, 0);
				params.height = 50;
				params.width = 50;											
				params.setMargins(lastX, lastY, 0, 0);
				button.setLayoutParams(params);
				button.clearAnimation();
						
			}
		});																								
		animationTranslate.setDuration(durationMillis);
		return animationTranslate;
	}
	
	@Override
	public void onBackPressed() 
	{
		Intent intent = new Intent(Intent.ACTION_MAIN);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.addCategory(Intent.CATEGORY_HOME);
		AseoZdpAseo.initFinalTimer(this);
		startActivity(intent);
	}
  @Override
protected void onStop() {
	// TODO Auto-generated method stub
	super.onStop();
}
		
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/115536.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • Java中Boolean是什么?

    Java中Boolean是什么?Java中的boolean其实就是c中的bool型(逻辑型)数据类型。在java中,boolean值只能是true和false,而不能用0和1代替,并且一定要小写。要注意到的是,数值的0、-0、特殊值的null、NaN、undefined以及空字符(””)都会被解释为false,其他值则会被解释为true。…

  • CURL 命令简介

    CURL 命令简介0概述curl是利用URL语法在命令行方式下工作的开源文件传输工具。它被广泛应用在Unix、多种Linux发行版中,并且有DOS和Win32、Win64下的移植版本。curl就是使用命令的方式来执行http协议的请求的工具。可以通过curl操作HTTP的GET/POST/PUT/DELETE方法。1常用方式访问一个网页curlwww.baidu.com显示htt

  • LVS 负载均衡集群(一)| 超详细!一文带你了解 LVS 负载均衡集群

    LVS 负载均衡集群(一)| 超详细!一文带你了解 LVS 负载均衡集群前言如今,在各种互联网应用中,随着站点对硬件性能、响应速度、服务稳定性、数据可靠性等要求也越来越高,单台服务器也将难以无法承担所有的访问需求。当然了,除了使用性价比高的设备和专用负载分流设备外,还有一些其他选择来帮你解决此问题,就是搭建集群服务器通过整合多台普通的服务器设备并以同一个地址对外提供相同的服务,今天杰哥就带领大家学习企业中常用的一种群集技术——LVS。文章目录一、什么是LVS?…

  • CGLib简单入门

    CGLib简单入门一、CGlib简介        CGlib是一个强大的,高性能,高质量的Code生成类库。它可以在运行期扩展Java类与实现Java接口。 当然这些实际的功能是asm所提供的,asm又是什么?Java字节码操控框架,具体是什么大家可以上网查一查,毕竟我们这里所要讨论的是cglib。cglib就是封装了asm,简化了asm的操作,实现了在运行期动态生成新的class。 可能大家还感觉不到它的

  • 《零基础》MySQL NULL 值处理(二十一)

    《零基础》MySQL NULL 值处理(二十一)MySQL使用SQLSELECT命令及WHERE子句来读取数据表中的数据,但是当提供的查询条件字段为NULL时,该命令可能就无法正常工作。为了处理这种情况,MySQL提供了三大运算符:ISNULL:当列的值是NULL,此运算符返回true。 ISNOTNULL:当列的值不为NULL,运算符返回true。 <=>:比较操作符(不同于=运算符),当比较的的两个值相等或者都为NULL时返回true。关于NULL的条件比较运算是比较特殊的…

  • python的环境变量的设置,安装库的两种方法,pycharm解释器设置字体大小,在DOS下运行python,无法定位动态库「建议收藏」

    python的环境变量的设置,安装库的两种方法,pycharm解释器设置字体大小,在DOS下运行python,无法定位动态库「建议收藏」windons下的安装,环境变量的设置,pycharm的安装下载,字体的设置1.下载pycharm  a.下载地址https://www.7down.com/soft/336988.htmlb.pycharm安装成功后配置搜狗输入法,代码区输入时符合的切换c.pycharm创建记事本和文件目录2.python安装模块  安装第三…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号