介绍
这篇文章主要讲解了Android自定义观点实现直播点赞特效的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
由于开发的需要,需要开发类似直播点赞特效的需求,于是自定义观点来实现这种效果
案例图:
自定义观点
进口android.animation.Animator; 进口android.animation.AnimatorSet; 进口android.animation.ObjectAnimator; 进口android.animation.TypeEvaluator; 进口android.animation.ValueAnimator; 进口android.content.Context; 进口android.graphics.PointF; 进口android.graphics.drawable.Drawable; 进口android.util.AttributeSet; 进口android.view.View; 进口android.view.animation.AccelerateDecelerateInterpolator; 进口android.view.animation.AccelerateInterpolator; 进口android.view.animation.DecelerateInterpolator; 进口android.view.animation.Interpolator; 进口android.view.animation.LinearInterpolator; 进口android.widget.ImageView; 进口android.widget.RelativeLayout; 进口com.xinrui.ndkapp.R; 进口java.util.Random;/* * *由liuyong *数据:2017/8/8 * Github: https://github.com/MrAllRight *直播点赞的观点 */公开课GivePraiseView RelativeLayout{延伸 私人使用。LayoutParams LayoutParams;//图片布局参数 私人PointF mPointF0、mPointF1 mPointF2 mPointF3;//通过3阶贝塞尔曲线控制图片的移动轨迹 私人int mScreenWidth mScreenHeight;//屏幕宽高 私人可拉的[]mImageDrawables;//加载点赞红心图片,红黄蓝 私人int mDrawableWidth mDrawableHeight;//图片的宽高 私人随机mRandom=new随机(); 私人int数=0; 私人插入器[]插入器=new插入器[4]; 公共GivePraiseView(上下文语境){ 超级(上下文); init (); } 公共GivePraiseView(上下文语境、AttributeSet attrs int defStyleAttr) { 超级(上下文、attrs defStyleAttr); init (); } 公共GivePraiseView(上下文语境,AttributeSet attrs) { 超级(上下文,attrs); init (); } @Override 保护空白> & lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比; http://schemas.android.com/apk/res/android" & lt; RelativeLayout xmlns: android=?; android: layout_width=癿atch_parent" android: layout_height=癿atch_parent" android:背景=癅android:颜色/darker_gray"比; & lt; com.xinrui.ndkapp.view.GivePraiseView android: layout_width=癿atch_parent" android: layout_height=癿atch_parent"/比; & lt; !——& lt; com.xinrui.ndkapp.view.LoveLayout——比; & lt; !——android: layout_width=癿atch_parent"——比; & lt; !——android: layout_height=癿atch_parent"/祝辞——比; & lt;/RelativeLayout>
3。活动部分代码
进口android.app.Activity; 进口android.os.Bundle; 公开课GivePraiseActivity延伸活动{ @Override 保护无效alt=" Android自定义观点实现直播点赞特效的方法">p0坐标:x坐标((布局的宽,心形图片宽)除以2),y坐标(布局的高——心形图片高),这样获得的是顶部部水平中心点的坐标。
p1坐标:x坐标(横坐标中的随机位置),y坐标(布局一半的高度加上0到一半高度范围内的随机坐标+心形的高度的一半)。这样取到的横坐标是在布局宽度之内的随机坐标,纵坐标为整个路径高度中部以上的随机坐标。
p2坐标:与p1类似,横坐标是在布局宽度之内的随机坐标,纵坐标为整个路径高度中部以下的随机坐标。
p3坐标:控件底部中心点
知道4个坐标了,那么就可以开始计算路径Android自定义观点实现直播点赞特效的方法