Android形状:带有勾号的圆形
创始人
2024-10-12 16:00:36
0

要创建一个带有勾号的圆形形状,你可以使用自定义的Drawable来实现。以下是一个示例代码:

  1. 创建一个名为"CheckCircleDrawable"的类,继承自Drawable类:
public class CheckCircleDrawable extends Drawable {
    private Paint circlePaint;
    private Paint tickPaint;
    private float strokeWidth;
    private int circleColor;
    private int tickColor;

    public CheckCircleDrawable(float strokeWidth, int circleColor, int tickColor) {
        this.strokeWidth = strokeWidth;
        this.circleColor = circleColor;
        this.tickColor = tickColor;

        circlePaint = new Paint();
        circlePaint.setAntiAlias(true);
        circlePaint.setStyle(Paint.Style.STROKE);
        circlePaint.setStrokeWidth(strokeWidth);
        circlePaint.setColor(circleColor);

        tickPaint = new Paint();
        tickPaint.setAntiAlias(true);
        tickPaint.setStyle(Paint.Style.STROKE);
        tickPaint.setStrokeWidth(strokeWidth);
        tickPaint.setColor(tickColor);
    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        Rect bounds = getBounds();
        float centerX = bounds.exactCenterX();
        float centerY = bounds.exactCenterY();
        float radius = Math.min(centerX, centerY) - strokeWidth / 2;

        // 绘制圆形
        canvas.drawCircle(centerX, centerY, radius, circlePaint);

        // 绘制勾号
        Path tickPath = new Path();
        tickPath.moveTo(centerX - radius / 2, centerY);
        tickPath.lineTo(centerX - radius / 8, centerY + radius / 2);
        tickPath.lineTo(centerX + radius / 2, centerY - radius / 2);
        canvas.drawPath(tickPath, tickPaint);
    }

    @Override
    public void setAlpha(int alpha) {
        circlePaint.setAlpha(alpha);
        tickPaint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {
        circlePaint.setColorFilter(colorFilter);
        tickPaint.setColorFilter(colorFilter);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSPARENT;
    }
}
  1. 在你的Activity或Fragment中,使用CheckCircleDrawable作为View的背景:
CheckCircleDrawable checkCircleDrawable = new CheckCircleDrawable(5, Color.BLUE, Color.WHITE);

View view = findViewById(R.id.your_view_id);
view.setBackground(checkCircleDrawable);

这样,你就可以在你的View上显示一个带有勾号的圆形形状了。你可以根据需要调整画笔的宽度、填充颜色和勾号颜色。

相关内容

热门资讯

终于知道!wepoker开脚本... 自定义wepoker代打辅助机器人系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用...
科技通报!wepoker黑侠辅... 此外,数据分析德州(wepoker黑侠辅助器正版下载)辅助神器app还具备辅助透视行为开挂功能,通过...
1.9分钟了解!hhpoker... 1.9分钟了解!hhpoker是内部控制吗,wepoker透视最简单三个步骤,技巧教程(有挂辅助);...
总算了解!hhpoker到底可... 总算了解!hhpoker到底可以作弊码,pokemmo手机脚本辅助器,微扑克教程(有挂技巧);大神普...
2024教程!wepoker怎... 1、2024教程!wepoker怎么增加运气,pokemmo脚本辅助下载,高科技教程(有挂辅助)。2...
盘点一款!We poker辅助... 盘点一款!We poker辅助器下载,hhpoker到底可以作弊吗,透明挂教程(有挂神器)是由北京得...
玩家必看攻略!we-poker... 《玩家必看攻略!we-poker是什么软件,aapoker怎么开辅助器,插件教程(有挂技巧)》 aa...
玩家必看科普!约局吧开挂神器是... 玩家必看科普!约局吧开挂神器是真的吗,wepoker好友助力码,力荐教程(有挂技巧);《WPK辅助透...
交流学习经验!werplan辅... 自定义wepoker辅助真的假的系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
教程辅助!wepoker有没有... 教程辅助!wepoker有没有挂,hhpoker是正品吗,技巧教程(有挂软件);《WPK辅助透视》‌...