美文网首页Android技术知识程序员Android知识
模仿android版instagram双击点赞效果

模仿android版instagram双击点赞效果

作者: ldoublem | 来源:发表于2016-05-13 12:15 被阅读1163次

先上效果图


效果图.gif

实现双击的效果,然后将点赞的动画体现出来。

1 双击效果

Android sdk给我们提供了GestureDetecto这个类,GestureDetector这个类对外提供了两个接口:OnGestureListenerOnDoubleTapListener,还有一个内部类SimpleOnGestureListener

public class OnDoubleClick extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            //双击
            return false;
        }

        public boolean onSingleTapConfirmed(MotionEvent e) {
            //单击
            return false;
        }

    }

实例化GestureDetector

GestureDetector mGestureDetector = new GestureDetector(this, new OnDoubleClick());

将view的onTouch监听捕捉到

view.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent event) {
                return mGestureDetector.onTouchEvent(event);
            }
        });

双击操作捕捉到后就开始动画效果,这里用简单的ScaleAnimation

ScaleAnimation animation_ScaleAnimation = new ScaleAnimation(1.0f, 1.5f, 1.0f, 1.5f,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation_ScaleAnimation.setDuration(600);

相关文章

网友评论

    本文标题:模仿android版instagram双击点赞效果

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