仿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();
}
		
}

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

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

(0)
上一篇 2022年2月3日 上午7:00
下一篇 2022年2月3日 上午7:00


相关推荐

  • 2021纪念品csgo_csgo最便宜的开箱网站

    2021纪念品csgo_csgo最便宜的开箱网站2021已知目前最全的国内CSGO开箱网站大全!!incsgo国内CSGO饰品皮肤开箱网站官方链接:www.incsgo.gg注册登录自动免费获得$1.00美金取回状态:直接取回**优惠码:**csgogo(充值使用csgogo可增加5%充值金额)skinsdog狗网CSGO饰品皮肤开箱网站可直接取回官方链接:skinsdog.cc注册登录自动免费获得$0.8美金取回状态:直接取回**优惠码:**csgogo(注册使用送0.8美金)coolkaixiang.

    2022年10月6日
    3
  • 微信小程序页面跳转 回退页面api

    微信小程序页面跳转 回退页面api小程序如果 跳转url后 需要直接返回首页或者回退之前好几个页面,跳转url时用 wx.redirectTo设置好回退的参数即可。如果返回上一页时 跳转url时用 wx.navigateTo

    2022年8月19日
    7
  • 卡方检验x2什么意思_卡方检验和方差分析

    卡方检验x2什么意思_卡方检验和方差分析x2检验(chi-squaretest)或称卡方检验x2检验(chi-squaretest)或称卡方检验,是一种用途较广的假设检验方法。可以分为成组比较(不配对资料)和个别比较(配对,或同一对象

    2022年8月4日
    10
  • initramfs学习「建议收藏」

    initramfs学习「建议收藏」(一)helloworld一、initramfs是什么在2.6版本的linux内核中,都包含一个压缩过的cpio格式的打包文件。当内核启动时,会从这个打包文件中导出文件到内核的rootfs文件系统,然后内核检查rootfs中是否包含有init文件,如果有则执行它,作为PID为1的第一个进程。这个init进程负责启动系统后续的工作,包括定位、挂载“真正的”根文件系统设备(如果有的话)。

    2022年8月11日
    15
  • 欠采样和过采样_过采样和欠采样

    欠采样和过采样_过采样和欠采样欠采样和过采样简介 Introduction TheImbalance Okay theskewmayno

    2026年3月16日
    1
  • redis雪崩原因_什么是redis雪崩

    redis雪崩原因_什么是redis雪崩1、每天和技术水友,提三个问题。不喜勿喷。redis雪崩效应:1、redis缓存的时间同时失效或者无效的key,落地到db层,导致db层压力过大,引发一系列的功能不可用解决措施:以下穷逼公司解决方案:1、redis设置时间加入随机时间2、数据量少考虑加入本地缓存3、限流(TODO:用户体验不好)4、互斥锁(TODO:用的不好,系统分分钟down掉)5、定时任务(TODO:小心点,别乱塞)此乃富有公司最终解决方案6、加服务器(最终解决方案,一台不行加10台)…

    2025年11月16日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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