搜索
查看
编辑修改
首页
UNITY
NODEJS
PYTHON
AI
GIT
PHP
GO
CEF3
JAVA
HTML
CSS
搜索
很楠不爱3
这个屌丝很懒,什么也没留下!
关注作者
热门标签
jquery
HTML
CSS
PHP
ASP
PYTHON
GO
AI
C
C++
C#
PHOTOSHOP
UNITY
iOS
android
vue
xml
爬虫
SEO
LINUX
WINDOWS
JAVA
MFC
CEF3
CAD
NODEJS
GIT
Pyppeteer
article
热门文章
1
S3C2440 PWM设置_阐述s3c2440定时器产生pwm波形的工作过程
2
前端笔记:javascript小知识整理_js editor转funciton
3
C语言 printf 的用法总结(完善中)_int printf
4
SpringCloud微服务详解:java开发工程师等级划分_资深java开发工程师 springcloud
5
Docker容器常见面试题_容器面试题
6
真正弄懂存储虚拟化、软件定义存储_软件定义与虚拟化csdn
7
数字图像处理—图像分割—并行边界—利用边缘灰度不连续性(边缘)(边缘与导数)(边界闭合)_并行边界技术
8
【图形学】我理解的伽马校正(Gamma Correction)
9
python3---项目bwapp--对2017年的OWASP TOP 10中A1 injection sql 注入(get/search)进行Python3脚本实现_wapp2.top
10
通过easyExcel实现表格导入导出_easyexcelutil.formtemplatebuild
当前位置:
article
> 正文
超炫button按钮动画效果_button特效
作者:很楠不爱3 | 2024-02-16 11:26:34
赞
踩
button特效
今天从网上看到一个这样的效果,感觉很有创意,自己也搜集了一些资料,仿照着实现了一下。 下面就直接上源码:
首先看一下布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff">
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent" android:background="@drawable/splash_shadow"
android:layout_marginLeft="50dip" />
<RelativeLayout android:id="@+id/relativeLayout_top_bar"
android:layout_width="fill_parent" android:layout_height="40dip"
android:background="@drawable/qa_bar">
<ImageView android:layout_width="60dip"
android:layout_height="20dip" android:background="@drawable/qa_logo"
android:layout_centerInParent="true" />
</RelativeLayout>
<TextView android:layout_below="@id/relativeLayout_top_bar"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="20sp" android:text="Tap to Refresh"
android:layout_centerHorizontal="true" android:layout_marginTop="50dip" android:textStyle="bold"/>
<Button android:id="@+id/button_composer_sleep"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/composer_sleep"
android:layout_marginBottom="10dip" android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true">
</Button>
<Button android:id="@+id/button_composer_thought"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/composer_thought"
android:layout_marginBottom="10dip" android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true" android:layout_above="@id/button_composer_sleep">
</Button>
<Button android:id="@+id/button_composer_music"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/composer_music"
android:layout_marginBottom="10dip" android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true">
</Button>
<Button android:id="@+id/button_composer_place"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/composer_place"
android:layout_marginBottom="10dip" android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true" android:layout_above="@id/button_composer_music">
</Button>
<Button android:id="@+id/button_composer_with"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/composer_with"
android:layout_marginBottom="10dip" android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true" android:layout_above="@id/button_composer_place">
</Button>
<Button android:id="@+id/button_composer_camera"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/composer_camera"
android:layout_marginBottom="10dip" android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true" android:layout_above="@id/button_composer_with">
</Button>
<Button android:id="@+id/button_friends_delete"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/friends_delete"
android:layout_marginBottom="10dip" android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true" android:layout_above="@id/button_composer_camera">
</Button>
</RelativeLayout>
复制代码
实现button按钮动画效果的核心类:
import android.R.anim;
import android.app.Activity;
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;
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;
/** 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 Auto-generated method stub
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;
}
}
复制代码
其实就是在button点击的时候播放Tween动画。
这样就基本完成,参照上面的代码 自己也可以自行修改成自己喜欢的样式。
看一下在我手机上运行的效果:
声明:
本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:
https://www.wpsshop.cn/w/很楠不爱3/article/detail/92705
推荐阅读
article
uni
中将小程序页面
分享
给好友和朋友圈_
uni
app
<
button
open
-
type
=
"
shar...
1.小程序原生自带
分享
到朋友圈onShareAppMessage: function () { console.log(...
赞
踩
article
Bootstrap 快速入门之第八章 插件之模态框&工具提示&标签页&滚动监听_
<
<
em>div
<
/em>
<
em>class
<
/em>...
一:模态框1.基本实例 使用模态框的弹窗组件需要以下三层
<
em>div
<
/em>容器元素: 分别是modal(模态声明层)、dialog(...
赞
踩
article
QT
实现
带有
动画
效果的
switch
button
开关
按钮
动_qt
实现
按钮
背景
动画
过渡...
https://blog.csdn.net/xiezhongyuan07/article/details/9321778...
赞
踩
article
[
HTML
]Web前端开发技术17(
HTML
5
、
CSS3
、
JavaScript )
textarea
,...
表单概述 表单信息输入 单行文本输入框
、
密码框文本框 关于在不同浏览器中 显示宽度不同的解决问题 关于IE浏览器中默认文...
赞
踩
article
uniapp
-
vue3
-微信
小
程序
-
按钮
组wo-btn-
group
_
小
程序
button
-
group
...
采用
uniapp
-
vue3
实现, 是一款支持高度自定义的
按钮
组组件,支持H5、微信
小
程序
(其他
小
程序
未测试过,可自行尝试...
赞
踩
相关标签
bootstrap
html
css
前端
html5
计算机学习
javascript
css3
uni-app
微信小程序
vue.js
小程序