1、Math.atan()与Math.atan2()的区别

angle = Math.atan(slope)
复制代码

slope斜率值为y/x,返回值angle为一个角度的弧度制,因为角度的周期性,此方法不能很好的反应角度,应使用Math.atan2替换。

angle = Math.atan2(y,x)
复制代码

x是临边边长,y是对边边长。

弧度转角度方法:

    弧度 = 角度 * Math.PI / 180;角度 = 弧度 * 180 / Math.PI;
复制代码

计算两点间连线的倾斜角:

Math.atan2()函数返回的是点(x,y)和原点(0,0)之间直线的倾斜角,计算任意两点的切斜角,应使用Math.atan2(y2-y1,x2-x1)。

2、PathMeasure结合ValueAnimator实现轨迹绘制效果

关键方法:

PathMeasure#getLength():获取轨迹总长度

PathMeasure#getSegment(float startD, float stopD, Path dst, boolean startWithMoveTo):startD、stopD分别是轨迹长度值,dst是保存到的片段路径。

public class CirclePathView extends View {private int mWidth;private int mHeight;private PathMeasure mPathMeasure;private float mLength;private Path mDst;private float animatedValue;private Paint mPaint;private Path mPath;public CirclePathView(Context context) {this(context,null);}public CirclePathView(Context context, @Nullable AttributeSet attrs) {this(context, attrs,0);}public CirclePathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);initView();}@Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);mWidth = w;mHeight = h;mPath = new Path();mPath.addCircle(mWidth / 2,mHeight / 2,mWidth / 4,Path.Direction.CW);mPathMeasure = new PathMeasure();mPathMeasure.setPath(mPath,true);mLength = mPathMeasure.getLength();}private void initView() {mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);mPaint.setStyle(Paint.Style.STROKE);mPaint.setStrokeWidth(5);mPaint.setColor(Color.BLACK);mDst = new Path();ValueAnimator animator = ValueAnimator.ofFloat(1, 0);animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator animation) {animatedValue = (float) animation.getAnimatedValue();invalidate();}});animator.setDuration(2000);animator.setRepeatCount(ValueAnimator.INFINITE);animator.start();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);mDst.reset();mDst.lineTo(0,0);float stop = mLength * animatedValue;float start = (animatedValue - 0.5f > 0 ? (animatedValue - 0.5f) * 2 : 0f) * mLength;mPathMeasure.getSegment(start,stop,mDst,true);canvas.drawPath(mDst,mPaint);}
}复制代码

轨迹效果也可使用DashPathEffect,通过控制实线的偏移量来实现。

3、点赞-飘心效果

  • 获取一个间于min和max之间的随机值:
int randomNum = new Random().nextInt(max - min + 1) + min;
//int randomNum = new Random().nextInt(max) % (max - min + 1) + min; //好傻噢
复制代码
  • AS打开工程报错ssl peer shut down incorrectly:gradle版本问题。
  • GitHub飘心点赞项目:github.com/trc1993/And…

核心逻辑:确认红心起点、终点坐标(高度随机),创建2阶贝塞尔曲线,通过PathMeasure.getPosTan()和ValueAnimator,获取路径上每个点的坐标,再通过View#setTranslationX()和View#setTranslationY()移动红心。

    private void addFHeart(ImageView startLocationIv, Drawable floatDrawable) {int min = animMinWidth;int max = animMaxWidth;Random random = new Random();animWidth = random.nextInt(max - min + 1) + min;int min1 = animMinHeight;int max1 = animMaxHeight;Random random1 = new Random();animHeight = random1.nextInt(max1 - min1 + 1) + min1;final ImageView _floatIv = new ImageView(context);_floatIv.setImageDrawable(floatDrawable);RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(floatIconWidth, floatIconHeight);params.width = DisplayUtil.dip2px(context, floatIconWidth);params.height = DisplayUtil.dip2px(context, floatIconHeight);FRl.addView(_floatIv, params);int[] parentLocation = new int[2];FRl.getLocationInWindow(parentLocation);//得到起始图片的坐标(用于计算动画开始的坐标)int startLoc[] = new int[2];startLocationIv.getLocationInWindow(startLoc);//        三、正式开始计算动画开始/结束的坐标//起始点:图片起始点-父布局起始点+该图片的一半startX = startLoc[0] - parentLocation[0];startY = startLoc[1] - parentLocation[1];endX = startX;endY = startY - animHeight;firstControlX = startX - animWidth;firstControlY = startY - animHeight * 3 / 8;secondControlX = startX + animWidth;secondControlY = startY - animHeight * 5 / 8;Path path = new Path();path.moveTo(startX, startY);path.cubicTo(firstControlX, firstControlY, secondControlX, secondControlY, endX, endY);final PathMeasure mPathMeasure = new PathMeasure(path, false);//★★★属性动画实现(从0到贝塞尔曲线的长度之间进行插值计算,获取中间过程的距离值)AnimatorSet bouncer = new AnimatorSet();ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, mPathMeasure.getLength());ObjectAnimator anim = ObjectAnimator.ofFloat(_floatIv, "alpha", 1f, 0.1f);// 匀速线性插值器bouncer.setInterpolator(new LinearInterpolator());valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator animation) {// 当插值计算进行时,获取中间的每个值,// 这里这个值是中间过程中的曲线长度(下面根据这个值来得出中间点的坐标值)float value = (Float) animation.getAnimatedValue();Log.d("FloatHeartView", "value:" + value);// ★★★★★获取当前点坐标封装到mCurrentPosition// boolean getPosTan(float distance, float[] pos, float[] tan) :// 传入一个距离distance(0<=distance<=getLength()),然后会计算当前距// 离的坐标点和切线,pos会自动填充上坐标,这个方法很重要。mPathMeasure.getPosTan(value, mCurrentPosition, null);//mCurrentPosition此时就是中间距离点的坐标值// 移动的图片(动画图片)的坐标设置为该中间点的坐标_floatIv.setTranslationX(mCurrentPosition[0]);_floatIv.setTranslationY(mCurrentPosition[1]);}});bouncer.play(valueAnimator).with(anim);bouncer.setDuration(animDuration);bouncer.start();bouncer.addListener(new Animator.AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}//当动画结束后:@Overridepublic void onAnimationEnd(Animator animation) {
//                // 把移动的图片imageview从父布局里移除FRl.removeView(_floatIv);}@Overridepublic void onAnimationCancel(Animator animation) {}@Overridepublic void onAnimationRepeat(Animator animation) {}});}
复制代码

4、点赞-数字滚动+1效果

juejin.im/post/5c2190…

5、支付宝、微信、银联支付

juejin.im/post/596d97…

8:Math.atan2、PathMeasure、点赞飘心效果、点赞数字滚动+1效果、集成支付相关推荐

  1. 微信小程序实现直播间点赞飘心效果的示例代码

    微信小程序实现直播间点赞飘心效果的示例代码 https://blog.csdn.net/qappleh/article/details/83865874

  2. 直播app源代码 直播软件开发Android UI动画 仿直播点赞飘心动画效果

    直播app源代码 直播软件开发Android UI动画 仿直播点赞飘心动画效果 一个飘心的小动画,之前看也看到网上有很多轮子,但是感觉不是很符合我的需求,所以自己就凑活凑活搞出来一个,废话不多说先看图 ...

  3. android点赞动画仿twritter,Android仿直播特效之点赞飘心效果

    本文实例为大家分享了Android实现点赞飘心效果的具体代码,供大家参考,具体内容如下 一.概述 老规矩先上图 好了,基本就是这个样子,录完的视频用格式工厂转换完就这个样子了,将就看吧 二.定义我们自 ...

  4. 3.使用GSYVideoPlayer实现仿抖音视频播放以及点赞飘心效果

    原创GitHub地址: https://github.com/ZhangZiLiX/DouYinVideoDemo 1.build.gradle配置 applyplugin:'com.android. ...

  5. qt同时两个动画执行_Qt实现数字滚动动画效果

    自己开发了一个股票智能分析软件,功能很强大,需要的点击下面的链接获取: https://www.cnblogs.com/bclshuai/p/11380657.html Qt实现数字滚动动画效果 3. ...

  6. vue点赞飘心(实测可用)

    第一步:在vue项目里首先起一个叫flutter-hearts-zmt.js的js文件 /*** @ProjectName flutter-hearts-zmt* @Version 0.0.0* @A ...

  7. Vue组件——数字滚动抽奖效果

    闲话不多说(希望对大家有帮助),那就直接上代码吧 可调整数字滚动速度,可指定开奖延迟时间,可指定开奖数字,按个人需求自行改动(录了个效果供参考,临时找的录屏,表介意) 不一一精简了 组件代码 < ...

  8. php实现数字滚动效果,vue如何实现数字滚动增加效果?代码示例

    项目中需要做数字滚动增加的效果,一开始很懵,研究了一下原理,发现很简单,贴出来分享一下 ^_^ 数字滚动组件: 0 props: { time: { type: Number, default: 2 ...

  9. ios 横向滚轮效果_iOS列表滚动视差效果

    效果:UITableView滚动的时候会有动画加视差效果 一个未处理的列表.png 当cell出现的时候 -(void)tableView:(UITableView *)tableView willD ...

最新文章

  1. 【Vue】IView之table组件化学习(二)
  2. java io源码解读_Java IO源码分析(五)——CharArrayReader 和 CharArrayWriter
  3. C++语言之可重载运算符/不可重载运算符
  4. Hadoop冷热数据转换工具Sqoop
  5. linux解决病毒系列之一,删除十字符libudev.so病毒文件
  6. 石油化工设备维护检修规程_旋回破碎机横梁臂架、衬板、内外铜套检修步骤及设备检修维护要点...
  7. hdu 3461 Code Lock(并查集)2010 ACM-ICPC Multi-University Training Contest(3)
  8. SpringMCV结构
  9. VLFeat工具包在matlab使用方法
  10. Jetson TX1开发笔记(三):开发利器-Nsight Eclipse Edition
  11. 程序人生 - 王者荣耀重名代码
  12. DBSCAN聚类算法实用案例
  13. RadioButton 修改图片大小的方式
  14. java 字母金字塔_打印大写字母三角形
  15. 每日文献:2018-01-29
  16. Android 是Google开发的基于Linux平台的开源手机操作系统
  17. video网络页面播放器: 组件video-player-vue和video.js 常用库
  18. AutoCAD2008绿色版用法
  19. Python开发工具之Pycharm最新安装教程
  20. 浅谈JAVA程序破解

热门文章

  1. 自己动手实现的 Spring IOC 和 AOP - 上篇
  2. 熟悉Java String的使用,熟悉String的各种函数,Java中各种变量类型
  3. C++ 中常用数学函数
  4. Java/C语言/C++/Python/PHP运算符优先级
  5. 你最喜欢的一张美女图片?
  6. 浅谈尾递归的优化方式
  7. 编程之美-寻找发帖“水王”方法整理
  8. 大话设计模式(七 工厂不好用了?)
  9. golang Reflect包
  10. 基于angular4+ng-bootstrap+bootstrap+scss的后台管理系统界面