模仿android版instagram双击点赞效果

先上效果图


效果图.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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容