1

これは、私のカスタム ドローアブルがデフォルトでどのように見えるかです。

ここに画像の説明を入力

しかし、スクロールすると AppBarLayout と重なってしまいます。

ここに画像の説明を入力

Drawable のコードは次のようになります。

@Override
public void draw(@NonNull Canvas canvas) {

    // get drawable dimensions
    Rect bounds = getBounds();

    float width = bounds.right - bounds.left;
    float height = bounds.bottom - bounds.top;
    float w2 = width / 2;
    float h2 = height / 2;
    float radius = Math.min(w2, h2) - mStrokeWidth / 2;

    mPath.reset();
    mPath.addCircle(width / 2, height / 2, radius, Path.Direction.CW);
    canvas.clipPath(mPath);

    // draw background gradient

    float barHeight = height / themeColors.length;
    mRectF.left = 0;
    mRectF.top = 0;
    mRectF.right = width;
    mRectF.bottom = height;
    for (int i = 0; i < themeColors.length; i++) {
        mPaint.setColor(themeColors[i]);

        canvas.drawRect(0, i * barHeight, width, (i + 1) * barHeight, mPaint);
    }

    mRectF.set(0, 0, width, height);
    canvas.clipRect(mRectF, Region.Op.REPLACE);

    if (mStrokeWidth != 0)
        canvas.drawCircle(width / 2, height / 2, width / 2 - mStrokeWidth / 2, mStrokePaint);

}

サポート ライブラリのバージョン: 25.3.1、26.1.0

私が試したこと: - REPLACE ではなくクリッピング パスの異なる領域値 - 最初にパスの四角形をクリッピングし、次に円をクリッピングします。

これを修正するにはどうすればよいですか?

4

1 に答える 1