波浪线

public class WaveView extends View {

    private int screenWidth;
    private float xoffset = 0;
    private Path path;
    private Paint paint;

    public WaveView(Context context) {
        this(context,null);
    }

    public WaveView(Context context,  AttributeSet attrs) {
        this(context, attrs,-1);
    }

    public WaveView(Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        screenWidth = wm.getDefaultDisplay().getWidth();
        paint = new Paint();
        paint.setColor(Color.RED);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(5);
        paint.setStyle(Paint.Style.STROKE);
        path = new Path();
        ValueAnimator animator = ValueAnimator.ofFloat(0f,screenWidth);
        animator.setDuration(1000);
        animator.setRepeatCount(-1);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                xoffset = (float) animation.getAnimatedValue();
                invalidate();
            }
        });
        animator.start();


    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        path.reset();
        path.moveTo(0+xoffset, 500);
        path.quadTo(screenWidth / 4+xoffset, 300, screenWidth / 2+xoffset, 500);
        path.moveTo(screenWidth / 2+xoffset, 500);
        path.quadTo(screenWidth / 4 * 3+xoffset, 700, screenWidth+xoffset, 500);

        path.moveTo(0 + xoffset - screenWidth, 500);
        path.quadTo(screenWidth / 4 + xoffset - screenWidth, 300, screenWidth / 2 + xoffset - screenWidth, 500);
        path.moveTo(screenWidth / 2 + xoffset - screenWidth, 500);
        path.quadTo(screenWidth / 4 * 3 + xoffset - screenWidth, 700, screenWidth + xoffset - screenWidth, 500);


        canvas.drawPath(path, paint);

    }
}

<com.bw.fengye.bolangxian.WaveView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值