滑动和动画

滑动动画

参考 

手势滑动监听

滑动动画

float posX = 0, posY = 0, curPosX = 0, curPosY = 0;

imageView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                posX = event.getX();
                posY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                curPosX = event.getX();
                curPosY = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                if ((curPosX - posX > 0) && (Math.abs(curPosX - posX) > 100)) {
                    if (index > 0) {
                        moveImage(--index);
                        TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
                        animation.setRepeatMode(Animation.REVERSE);
                        animation.setDuration(500);
                        imageView.startAnimation(animation);
                    }
                } else if ((curPosX - posX < 0) && (Math.abs(curPosX-posX) > 100)) {
                    if (index < list_image.size() - 1) {
                        moveImage(++index);
                        TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
                        animation.setRepeatMode(Animation.REVERSE);
                        animation.setDuration(500);
                        imageView.startAnimation(animation);
                    }
                }
                break;
        }
        return true;
    }
});

 虽然动画很酷,但也只是动画,和图库的拖动切换照片体验差很多。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值