广告
返回顶部
首页 > 资讯 > 移动开发 >Android仿荷包APP启动动画
  • 238
分享到

Android仿荷包APP启动动画

app启动app动画Android 2022-06-06 04:06:12 238人浏览 泡泡鱼
摘要

用荷包App的时候发现启动动画做的挺好玩的,于是便模仿实现了一下。 gif效果图: animation.gif 实现思路: 仔细观察,可以看出动画的执行分为两个阶段:

用荷包App的时候发现启动动画做的挺好玩的,于是便模仿实现了一下。

gif效果图:


animation.gif

实现思路:

仔细观察,可以看出动画的执行分为两个阶段:
第一阶段为硬币掉落。
第二阶段为钱包反弹。

布局xml文件如下:


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:Android="Http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity">
  <ImageView
    android:id="@+id/coin_iv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@mipmap/coin"/>
  <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="70dp"
    android:layout_marginLeft="70dp"
    android:src="@mipmap/version"/>
  <ImageView
    android:id="@+id/wallet_iv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@mipmap/wallet"/>
  <Button
    android:id="@+id/start_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|bottom"
    android:layout_marginBottom="10dp"
    android:text="start"/>
</FrameLayout>

硬币掉落:

硬币掉落的过程中执行两种动画,位移和旋转。
位移动画使用了补间动画,xml文件如下:


<?xml version="1.0" encoding="utf-8"?>
<translate
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:fromYDelta="-50%p"
  android:interpolator="@android:anim/accelerate_interpolator"
  android:toYDelta="0%"/>

旋转动画采用了重写Animation并利用android.hardware.Camera类来实现。


public class ThreeDRotateAnimation extends Animation { 
 int centerX, centerY; 
 Camera camera = new Camera(); 
  @Override
  public void initialize(int width, int height, int parentWidth, int parentHeight) {  
  super.initialize(width, height, parentWidth, parentHeight);  
  // 中心点坐标
  centerX = width / 2;  
  centerY = height / 2; 
  setDuration(500);  
  setInterpolator(new LinearInterpolator()); 
 }  
@Override  
protected void applyTransfORMation(float interpolatedTime, Transformation t) {  
  final Matrix matrix = t.getMatrix();
  camera.save(); 
  // 绕y轴旋转
  camera.rotateY(360 * interpolatedTime);  
  camera.getMatrix(matrix);  
  // 设置翻转中心点 
  matrix.preTranslate(-centerX, -centerY); 
  matrix.postTranslate(centerX, centerY);   
  camera.restore();  
 }
}

这里简单说下animation里面的preTranslate和postTranslate方法,preTranslate是指在rotateY前平移,postTranslate是指在rotateY后平移,注意他们参数是平移的距离,而不是平移目的地的坐标!
由于旋转是以(0,0)为中心的,所以为了把硬币的中心与(0,0)对齐,就要preTranslate(-centerX, -centerY), rotateY完成后,调用postTranslate(centerX, centerY),再把图片移回来,这样看到的动画效果就是硬币从中心不停的旋转了。
最后同时执行以上两种动画,实现掉落旋转效果。


private void startCoin() {
// 掉落
Animation animationTranslate = AnimationUtils.loadAnimation(this,R.anim.anim_top_in);
// 旋转
ThreeDRotateAnimation animation3D = new ThreeDRotateAnimation();
animation3D.setRepeatCount(10);
AnimationSet animationSet = new AnimationSet(true);
animationSet.setDuration(800);
animationSet.addAnimation(animation3D);
animationSet.addAnimation(animationTranslate);
mCoinIv.startAnimation(animationSet);
}

钱包反弹:

在执行硬币掉落的同时,启动一个ValueAnimator动画,来判断钱包反弹的时机。


private void setWallet() {
final ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
valueAnimator.setDuration(800);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
  @Override  public void onAnimationUpdate(ValueAnimator animation) {
    float fraction = animation.getAnimatedFraction();
    // 大概掉落到钱包的上边缘位置的时候,取消ValueAnimator动画,并执行钱包反弹效果
    if (fraction >= 0.75) {
      valueAnimator.cancel();
      startWallet();
    } 
  }});
valueAnimator.start();
}

最后执行钱包反弹效果动画,这里采用了ObjectAnimator 。


private void startWallet() {
  // x轴缩放
  ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(mLoGoIv, "scaleX", 1, 1.1f, 0.9f, 1);
  objectAnimator1.setDuration(600);
  // y轴缩放 
  ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(mLogoIv, "scaleY", 1, 0.75f, 1.25f, 1);
  objectAnimator2.setDuration(600);
  AnimatorSet animatorSet = new AnimatorSet();
  animatorSet.setInterpolator(new LinearInterpolator()); 
  // 同时执行x,y轴缩放动画 
  animatorSet.playTogether(objectAnimator1, objectAnimator2);
  animatorSet.start();}

这样一个简单的荷包启动动画效果就差不多出来了,唯一遗憾的是对钱包进行y轴缩放的时候会对整个y轴进行缩放,要想保持钱包底部不动,只有钱包上部反弹,暂时还没有想到什么好的方法,小弟不才还望大神赐教!谢谢!

完整源码

完整源码在GitHub
如果觉得还不错,记得star╰( ̄▽ ̄)╮哟~

您可能感兴趣的文章:Android编程之简单启动画面实现方法Android简单实现启动画面的方法Android软件启动动画及动画结束后跳转的实现方法Android启动画面的实现方法Android 避免APP启动闪黑屏的解决办法(Theme和Style)Android优化应用启动速度详解Android中App的启动界面Splash的编写方法Android app启动时黑屏或者白屏的原因及解决办法Android启动引导页使用ViewPager实现


--结束END--

本文标题: Android仿荷包APP启动动画

本文链接: https://www.lsjlt.com/news/22268.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android仿荷包APP启动动画
    用荷包App的时候发现启动动画做的挺好玩的,于是便模仿实现了一下。 gif效果图: animation.gif 实现思路: 仔细观察,可以看出动画的执行分为两个阶段: ...
    99+
    2022-06-06
    app启动 app 动画 Android
  • 使用Android如何模仿APP启动动画
    今天就跟大家聊聊有关使用Android如何模仿APP启动动画,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。效果图:animation.gif实现思路:仔细观察,可以看出动画的执行分为...
    99+
    2023-05-31
    android 动动 pp
  • Android获取App冷启动、热启动时间
    启动模拟器或者连接手机,通过adb命令的方式获取App冷启动、热启动时间。 启动App的adb命令: adb shell am start -W packagename/绝对路径下的MainActivity -W:启动完成之后,返回启动耗时...
    99+
    2023-10-26
    android adb 性能优化
  • Android APP启动方式、启动流程及启动优化分析
    本文章向大家介绍Android app应用启动的一些相关知识,包括app启动方式、app启动流程和app启动优化等知识!  app应用启动方式 1、冷启动  ...
    99+
    2022-06-06
    app启动 优化 app Android
  • Android APP启动时间测试
      对于app的性能测试,启动时间是个重要指标,启动时间分为两种情况,一种是冷启动时间(通常是系统重启,即在启动前没有该app进程的情况),另一种是热启动,即app从被切换...
    99+
    2022-06-06
    app app启动 测试 Android
  • Android app启动节点与上报启动的方法
    本文小编为大家详细介绍“Android app启动节点与上报启动的方法”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android app启动节点与上报启动的方法”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一...
    99+
    2023-06-30
  • Android如何实现过渡动画、引导页 Android判断是否第一次启动App
    这篇文章主要介绍了Android如何实现过渡动画、引导页 Android判断是否第一次启动App,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。目前的App在安装后,第一次打开...
    99+
    2023-05-30
  • Android app启动节点与上报启动实例详解
    目录app启动的关键节点启动时间怎么算方案1: 参考firebase:方案2 : ams总结app启动的关键节点 经常利用content provider 和Androidx里的 s...
    99+
    2022-11-13
  • Android adb命令 关闭app 和 启动app 还有重启app命令
    以下是Android中使用adb命令关闭应用程序、启动应用程序和重启应用程序的方法: 1.关闭应用程序 使用以下命令可以关闭正在运行的应用程序: adb shell am force-stop package_name 其中,package...
    99+
    2023-08-20
    android adb
  • android仿爱奇艺加载动画实例
    本篇文章介绍了android仿爱奇艺加载动画实例,具体代码如下: 效果图: 用到的知识点: Path ValueAnimator 如果对Path和ValueAnima...
    99+
    2022-06-06
    爱奇艺 动画 Android
  • Android 仿微信小程序入口动画
    目录效果对比流程分析自定义ViewGroup小程序缩放比例值计算动画遮罩MainActivity效果对比 微信原版 仿照效果 流程分析 自定义ViewGroup 整个布局是通...
    99+
    2022-11-12
  • Android中PathMeasure仿支付宝支付动画
    前言在 Android 自定义 View 中,Path 可能用的比较多,PathMeasure 可能用的比较少,就我而言,以前也没有使用过 PathMeasure 这个 api,看到别人用 PathMeasure 和 ValueAnimat...
    99+
    2023-05-30
    android pathmeasure 支付宝
  • android开机自动启动app的解决方法
    经过多次尝试之后,终于找到了开机自动启动App的解决方法 开机后会停留在锁屏页面,且短时间内如果没有进行解锁操作,屏幕会进入休眠状态,所以启动APP时需要先唤醒屏幕和解锁屏幕 定义一...
    99+
    2022-11-13
  • Android如何获取APP启动时间
    目录1.通过看logcat下的日志2.通过adb命令3.通过写代码获取1.通过看logcat下的日志 2.通过adb命令 3.通过写代码获取 3.1写一个工具类打印系统时间 ...
    99+
    2022-11-12
  • Android APP启动时间优化介绍
    APP启动时间优化首先要知道入伙获取APP启动时间,可以看我的这篇文章:Android 获取APP启动时间 然后就是想办法降低启动时间 1.在Application的onCreate...
    99+
    2022-11-12
  • Android仿ViVO X6 极速闪充动画效果
    一直都在看自定义View,经过一个星期的坚持,基本上能够写出一些比较实用的控件效果了,今天天气太热,就待在家里玩手机,然后手机没电了,在充电的时候,看到了手机的充电动画,觉得挺...
    99+
    2022-06-06
    vivo 动画 Android
  • Android之仿美团加载数据帧动画
    一:先来张效果图(这里是GIF动画,我就截屏的所有没有动画,实际是动的): 二:实现步骤: 1、xml布局 <?xml version="1.0" enco...
    99+
    2022-06-06
    数据 动画 Android
  • Android自定义View仿微博运动积分动画效果
    自定义View一直是自己的短板,趁着公司项目不紧张的时候,多加强这方面的练习。这一系列文章主要记录自己在自定义View的学习过程中的心得与体会。 刷微博的时候,发现微博运动界面...
    99+
    2022-06-06
    view 运动 动画 Android
  • Android实现app开机自启动功能
    本文实例为大家分享了Android实现app开机自启动的具体代码,供大家参考,具体内容如下 最近要做个大屏的开发板程序,需要长期稳定运行,并开机自启运行此软件。 废话不多说,上...
    99+
    2022-06-07
    启动 app Android
  • Android广播实现App开机自启动
    本文实例为大家分享了Android广播实现App开机自启动的具体代码,供大家参考,具体内容如下 一、概括 在安卓中,想要实现app开机自动启动,需要实现拦截广播android....
    99+
    2022-06-07
    启动 android广播 app Android
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作