美文网首页
仿抖音双击点赞效果

仿抖音双击点赞效果

作者: 木叶纷飞 | 来源:发表于2018-08-17 16:42 被阅读0次

/**

* 创建者    yf

* 创建时间  2018/8/17 11:51

* 描述       ${TODO}

*/

public class PraiseLayout extends FrameLayout{

    //点击次数

    private int count = 0;

    //第一次点击时间

    private long firstClick = 0;

    //第二次点击时间

    private long secondClick = 0;

    /**

    * 两次点击时间间隔,单位毫秒

    */

    private final int totalTime = 300;

    Drawable drawable;

    public PraiseLayout(@NonNull Context context) {

        super(context);

        Drawable var10001 = this.getResources().getDrawable(R.mipmap.ic_heart);

        this.drawable = var10001;

        this.setClipChildren(false);

    }

    public PraiseLayout(@NonNull Context context, @Nullable AttributeSet attrs) {

        super(context, attrs);

        Drawable var10001 = this.getResources().getDrawable(R.mipmap.ic_heart);

        this.drawable = var10001;

        this.setClipChildren(false);

    }

    public PraiseLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

        super(context, attrs, defStyleAttr);

        Drawable var10001 = this.getResources().getDrawable(R.mipmap.ic_heart);

        this.drawable = var10001;

        this.setClipChildren(false);

    }

    @Override

    public boolean onTouchEvent(MotionEvent event) {

        if (MotionEvent.ACTION_DOWN == event.getAction()) {

            count++;

            if (1 == count) {

                //记录第一次点击时间

                firstClick = System.currentTimeMillis();

            } else if (2 == count) {

                //记录第二次点击时间

                secondClick = System.currentTimeMillis();

                //判断二次点击时间间隔是否在设定的间隔时间之内

                if (secondClick - firstClick < totalTime) {

                    float x = event.getX();

                    float y = event.getY();

                    addHeartView(x,y);

                    count = 0;

                    firstClick = 0;

                } else {

                    firstClick = secondClick;

                    count = 1;

                }

                secondClick = 0;

            }

        }

        return super.onTouchEvent(event);

    }

    private void addHeartView(float x, float y) {

        LayoutParams lp = new LayoutParams(this.drawable.getIntrinsicWidth(), this.drawable.getIntrinsicHeight());

        lp.leftMargin = (int)(x - (float)(this.drawable.getIntrinsicWidth() / 2));

        lp.topMargin = (int)(y - (float)this.drawable.getIntrinsicHeight());

        final ImageView img = new ImageView(this.getContext());

        img.setScaleType(ImageView.ScaleType.MATRIX);

        Matrix matrix = new Matrix();

        matrix.postRotate(this.getRandomRotate());

        img.setImageMatrix(matrix);

        img.setImageDrawable(this.drawable);

        img.setLayoutParams((android.view.ViewGroup.LayoutParams)lp);

        this.addView((View)img);

        AnimatorSet animSet = this.getShowAnimSet(img);

        final AnimatorSet hideSet = this.getHideAnimSet(img);

        animSet.start();

        animSet.addListener((new AnimatorListenerAdapter() {

            @Override

            public void onAnimationEnd(@Nullable Animator animation) {

                super.onAnimationEnd(animation);

                hideSet.start();

            }

        }));

        hideSet.addListener((new AnimatorListenerAdapter() {

            @Override

            public void onAnimationEnd(@Nullable Animator animation) {

                super.onAnimationEnd(animation);

                PraiseLayout.this.removeView(img);

            }

        }));

    }

    private AnimatorSet getHideAnimSet(ImageView view) {

        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", new float[]{1.0F, 0.1F});

        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", new float[]{1.0F, 2.0F});

        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", new float[]{1.0F, 2.0F});

        ObjectAnimator translation = ObjectAnimator.ofFloat(view, "translationY", new float[]{0.0F, -150.0F});

        AnimatorSet animSet = new AnimatorSet();

        animSet.playTogether(new Animator[]{alpha, scaleX, scaleY, translation});

        animSet.setDuration(500);

        return animSet;

    }

    private AnimatorSet getShowAnimSet(ImageView imageView) {

        ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", new float[]{1.2F, 1.0F});

        ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", new float[]{1.2F, 1.0F});

        AnimatorSet animSet = new AnimatorSet();

        animSet.playTogether(new Animator[]{scaleX, scaleY});

        animSet.setDuration(100);

        return animSet;

    }

    private final float getRandomRotate() {

        return (float)((new Random()).nextInt(20) - 10);

    }

}

相关文章

  • 仿抖音双击点赞效果

    /** * 创建者 yf * 创建时间 2018/8/17 11:51 * 描述 ${TODO} */...

  • Flutter 仿抖音效果 (二) 界面布局

    Flutter 仿抖音效果 (一) 全屏点爱星Flutter 仿抖音效果 (二) 界面布局[Flutter 仿抖音...

  • 网络兼职的工作有什么?网络兼职有什么推荐吗?

    抖音双击多少钱一个,抖音双击量在线刷!双击也就是咱们平时说的点赞,点赞其实和粉丝相比较起来还是便宜许多,可以加qq...

  • 仿抖音点赞效果----LovePraise

    最近看了下抖音的点赞效果,感觉很不错,模仿了下 这是效果图 原理很简单,通过手指触摸屏幕的xy轴来做心形图片的动画...

  • 仿抖音的点赞效果

    最近抖音App是真的很火,作为一个小宅Android Coder,看到抖音那么火肯定是要下载观摩的,被上面众多妹子...

  • 【Flutter应用】Flutter精仿抖音开源

    flutter_tiktok Flutter精仿抖音开源了,左滑搜索,右滑个人中心,上下滑动刷视频,双击点赞冒爱心...

  • 2018-12-22

    招聘326个抖音、快手视频作品点赞员 ①工作内容:给商家指定的快手抖音用户作品双击点赞,帮作品上热门涨粉 ②点赞一...

  • 抖音APP双击点赞效果实现

    首先来分析一下效果特点:1.双击屏幕任意位置,就生成一个心动图 2.心动图不断放大 3.心动图逐渐消失。 实现步骤...

  • 仿抖音之——点赞动画

    我这里做的是一个仿抖音点赞的动画,监听双击事件,在双击位置添加图片,对其进行一系列的缩放、移动、旋转、透明度的动画...

  • iOS仿抖音—评论视图滑动消失

    iOS仿抖音短视频 iOS仿抖音—左右滑动切换效果iOS仿抖音—上下滑动播放视频iOS仿抖音—评论视图滑动消失 前...

网友评论

      本文标题:仿抖音双击点赞效果

      本文链接:https://www.haomeiwen.com/subject/hartiftx.html