欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自定义Drawable

程序员文章站 2024-03-24 08:37:58
...

## 重写draw ##

@Override
    public void draw(Canvas canvas) {
        int height = canvas.getHeight();
        int width = canvas.getWidth();
        //设置渐变色
        LinearGradient linearGradient = new LinearGradient(width / 2, 0, width / 2,      canvas.getHeight(), mBgColor, 0xffffffff, Shader.TileMode.MIRROR);

        mBgPaint.setShader(linearGradient);

        canvas.drawRect(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), mBgPaint);

        int radius = DisplayUtil.dip2px(mContext, 38);
        paint.setColor(0x4dffffff);
        canvas.drawCircle(0, height / 5 * 2 - 28, radius, paint);

        radius = DisplayUtil.dip2px(mContext, 20);
        paint.setColor(0x1affffff);
        canvas.drawCircle(width / 3, 0, radius, paint);

        radius = DisplayUtil.dip2px(mContext, 18);
        paint.setColor(0x4dffffff);
        canvas.drawCircle(width / 5 * 3, height / 4, radius, paint);

        radius = DisplayUtil.dip2px(mContext, 68);
        paint.setColor(0x33ffffff);
        canvas.drawCircle(width , 0, radius, paint);

    }
相关标签: drawable