Skip to content

初始化,默认关闭,没画关闭颜色 #30

Description

@mudao

初始化的时候,ondraw中代码不执行,

    if (offLineWidth > 0) {
        final float cy = offLineWidth * 0.5f;
        rect.set(spotX - cy, centerY - cy, endX + cy, centerY + cy);
        paint.setColor(offColor);
        canvas.drawRoundRect(rect, cy, cy, paint);
    }

因为offLineWidth在onlayout中被赋值为0.建议修复.

@Override
protected void onLayout(boolean changed, int left, int top, int right,
    super.onLayout(changed, left, top, right, bottom);

    final int width = getWidth();
    final int height = getHeight();

    radius = Math.min(width, height) * 0.5f;
    centerY = radius;
    startX = radius;
    endX = width - radius;
    spotMinX = startX + borderWidth;
    spotMaxX = endX - borderWidth;
    spotSize = height - 4 * borderWidth;
    spotX = toggleOn ? spotMaxX : spotMinX;
    offLineWidth = 0;

}

可以把这行offLineWidth = 0;改为调用calculateEffect(toggleOn ? 1 : 0);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions