自定义波浪View,使头像跟着波浪背景浮动

先上效果图:


自定义波浪View:

通过正余弦自定义View 实现水波浪效果:

 double ω = 2 * Math.PI / getWidth();
        mAbovePath.moveTo(getLeft(), getBottom());
        mBelowWavePath.moveTo(getLeft(), getBottom());
        for (float x = 0; x <= getWidth(); x += 20) {
            y = (float) (rangeY * Math.cos(ω * x + φ) + 8);
            y2 = (float) (rangeY * Math.sin(ω * x + φ));
            mAbovePath.lineTo(x, y);
            mBelowWavePath.lineTo(x, y2);
            //回调 把y坐标的值传出去(在activity里面接收让图片随波浪一起摇摆)
            if (mWaveAnimationListener != null)
                mWaveAnimationListener.OnWaveAnimation(y);
        }
        mAbovePath.lineTo(getRight(), getBottom());
        mBelowWavePath.lineTo(getRight(), getBottom());

        canvas.drawPath(mAbovePath, mAboveWavePaint);
        canvas.drawPath(mBelowWavePath, mBelowWavePaint);

在Activity中监听自定义view的波动幅度,使图片随着上下浮动;

demo下载地址

点击打开链接

http://download.csdn.net/download/shanshan_1117/10255755

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值