仿抖音点赞效果实现 ——————自定义View
玩过抖音的人应该都知道抖音的点赞效果挺酷炫的,而作为码农我们一定想知道它是怎么实现的。先上效果图:
实现原理非常的简单,直接上代码:
/*** Description: 自定义 仿抖音动画类* Data:2018/12/7-下午2:21* Email:as752497576@gmail.com* Author: feipeng*/ public class YALikeAnimationView extends RelativeLayout {private Context mContext;float[] num = {-30, -20, 0, 20, 30};//随机心形图片角度private float dispatchXPosition;private float dispatchYPosition;public YALikeAnimationView(Context context) {super(context);initView(context);}public YALikeAnimationView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);initView(context);}public YALikeAnimationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);initView(context);}private void initView(Context context) {mContext = context;}@Overridepublic boolean onTouchEvent(MotionEvent ev) {dispatchXPosition = ev.getX();dispatchYPosition = ev.getY();return super.onTouchEvent(ev);}public void startAnimation(){final ImageView imageView = new ImageView(getContext());LayoutParams params = new LayoutParams(300, 300);params.leftMargin = (int) dispatchXPosition - 150;params.topMargin = (int) dispatchYPosition - 300;imageView.setImageDrawable(getResources().getDrawable(R.mipmap.icon_heart));imageView.setLayoutParams(params);addView(imageView);AnimatorSet animatorSet = new AnimatorSet();animatorSet.play(scale(imageView, "scaleX", 2f, 0.9f, 100, 0)).with(scale(imageView, "scaleY", 2f, 0.9f, 100, 0)).with(rotation(imageView, 0, 0, num[new Random().nextInt(4)])).with(alpha(imageView, 0, 1, 100, 0)).with(scale(imageView, "scaleX", 0.9f, 1, 50, 150)).with(scale(imageView, "scaleY", 0.9f, 1, 50, 150)).with(translationY(imageView, 0, -600, 800, 400)).with(alpha(imageView, 1, 0, 300, 400)).with(scale(imageView, "scaleX", 1, 3f, 700, 400)).with(scale(imageView, "scaleY", 1, 3f, 700, 400));animatorSet.start();animatorSet.addListener(new AnimatorListenerAdapter() {@Overridepublic void onAnimationEnd(Animator animation) {super.onAnimationEnd(animation);removeViewInLayout(imageView);}});}public static ObjectAnimator scale(View view, String propertyName, float from, float to, long time, long delayTime) {ObjectAnimator translation = ObjectAnimator.ofFloat(view, propertyName, from, to);translation.setInterpolator(new LinearInterpolator());translation.setStartDelay(delayTime);translation.setDuration(time);return translation;}public static ObjectAnimator translationX(View view, float from, float to, long time, long delayTime) {ObjectAnimator translation = ObjectAnimator.ofFloat(view, "translationX", from, to);translation.setInterpolator(new LinearInterpolator());translation.setStartDelay(delayTime);translation.setDuration(time);return translation;}public static ObjectAnimator translationY(View view, float from, float to, long time, long delayTime) {ObjectAnimator translation = ObjectAnimator.ofFloat(view, "translationY", from, to);translation.setInterpolator(new LinearInterpolator());translation.setStartDelay(delayTime);translation.setDuration(time);return translation;}public static ObjectAnimator alpha(View view, float from, float to, long time, long delayTime) {ObjectAnimator translation = ObjectAnimator.ofFloat(view, "alpha", from, to);translation.setInterpolator(new LinearInterpolator());translation.setStartDelay(delayTime);translation.setDuration(time);return translation;}public static ObjectAnimator rotation(View view, long time, long delayTime, float... values) {ObjectAnimator rotation = ObjectAnimator.ofFloat(view, "rotation", values);rotation.setDuration(time);rotation.setStartDelay(delayTime);rotation.setInterpolator(new TimeInterpolator() {@Overridepublic float getInterpolation(float input) {return input;}});return rotation;} }
OK!完美实现!最后贴上调用方法
YALikeAnimationView ya = findViewById(R.id.YALikeAnimationView); ya.startAnimation();
仿抖音点赞效果实现 ——————自定义View相关推荐
- 基于android的高仿抖音,Android仿抖音列表效果
本文实例为大家分享了Android仿抖音列表效果的具体代码,供大家参考,具体内容如下 当下抖音非常火热,是不是也很心动做一个类似的app吗? 那我们就用RecyclerView实现这个功能吧,关于内存 ...
- android仿抖音礼物列表实现,Android仿抖音列表效果
本文实例为大家分享了Android仿抖音列表效果的具体代码,供大家参考,具体内容如下 当下抖音非常火热,是不是也很心动做一个类似的app吗? 那我们就用RecyclerView实现这个功能吧,关于内存 ...
- android仿抖音关注列表,Android仿抖音列表效果
本文实例为大家分享了Android仿抖音列表效果的具体代码,供大家参考,具体内容如下 当下抖音非常火热,是不是也很心动做一个类似的app吗? 那我们就用RecyclerView实现这个功能吧,关于内存 ...
- Android高仿抖音滚动聊天,Android仿抖音列表效果
本文实例为大家分享了Android仿抖音列表效果的具体代码,供大家参考,具体内容如下 当下抖音非常火热,是不是也很心动做一个类似的app吗? 那我们就用RecyclerView实现这个功能吧,关于内存 ...
- Android 抖音爱心动画,Android自定义View实现抖音飘动红心效果
本文实例为大家分享了Android自定义View实现抖音飘动红心效果的具体代码,供大家参考,具体内容如下 自定义View--抖音飘动红心 效果展示 动画效果 使用自定义view完成红心飘动效果 Vie ...
- iOS 仿抖音点赞动画效果
1. 概述 最近看到抖音点赞爱心的动画效果比较好,出于好奇,自己也研究仿照动画效果写了一个,不喜欢的朋友可不要喷我噢
- Android仿抖音主页效果实现
目录 写在前面 一.准备工作 1.1.主页面布局 1.2.列表Item布局 1.3.列表Item适配器 二.自定义LayoutManager 三.实现播放 补充:源码地址:https://github ...
- iOS仿抖音点赞动画、波浪图、主张图、3D旋转、图片处理、播放器等源码 1
iOS精选源码 iOS 一个异步渲染TextKit 写个女朋友的生日礼物codeGift 3D旋转 仿抖音小视频点赞动画 高德地图SDK二次封装,完美适配iOS11. iOS图表二次定制 - 波浪折线 ...
- iOS仿抖音点赞动画、波浪图、主张图、3D旋转、图片处理、播放器等源码
iOS精选源码 iOS 一个异步渲染TextKit 写个女朋友的生日礼物codeGift 3D旋转 仿抖音小视频点赞动画 高德地图SDK二次封装,完美适配iOS11. iOS图表二次定制 - 波浪折线 ...
最新文章
- 2018-08-12 长大
- java equal 不等于_java Integer判断相等只能使用equals(不能使用==)
- mysql添加字段时定义候选键_MySQL 表约束
- spring boot缓存_Spring Boot和缓存抽象
- React JS 组件间沟通的一些方法
- C#的变迁史02 - C# 2.0篇
- 接口测试工具--apipost脚本讲解
- JSValidation 1.0b4 发布了!
- 【番外篇】ASP.NET MVC快速入门之免费jQuery控件库(MVC5+EF6)
- poj 2352 Stars 树状数组
- ble连接过程建立_BLE蓝牙协议 — BLE连接建立过程梳理
- 电脑html动态桌面壁纸制作,动态桌面软件《Wallpaper Engine》 让你的电脑桌面动起来!...
- ad20中如何在pcb里查找器件,AD中原理图如何查找相应的元件?
- chromecast 断电重启后时间错误
- 张驰咨询:关于企业选择六西格玛绿带培训人员,你需要知道这些
- 2022年中国智能家居产业链图谱 | 产业链全景图
- BLDC电机中的死区时间究竟是什么?
- Yocto OpenCV交叉编译
- matlab 矩阵中最小的数,计算矩阵中最小的N个数值
- RK3588快速上手 | 01-RK3588开发板快速上手