【问题标题】:Filling a custom shape with Android API Level 1 Path Calls使用 Android API 1 级路径调用填充自定义形状
【发布时间】:2016-05-24 06:11:23
【问题描述】:

我正在尝试创建一个需要填充的自定义形状。我不能使用“arcTo”方法,只能使用 moveTo、lineTo 和 addArc。

这是我的代码...

            bubblePaintOutline = new Paint();
            bubblePaintOutline.setColor(Color.BLACK);
            bubblePaintOutline.setStyle(Paint.Style.FILL_AND_STROKE);
            bubblePaintOutline.setStrokeWidth(10f);

            outlinePath.moveTo(bubbleRect.left, bubbleRect.top);
            outlinePath.addArc(new RectF(bubbleRect.left, bubbleRect.top, bubbleRect.left + (2 * margin), bubbleRect.top + (2 * margin)), 180, 90f);
            outlinePath.moveTo(bubbleRect.left+(margin),bubbleRect.top);
            outlinePath.lineTo(bubbleRect.right-(margin),bubbleRect.top);
            outlinePath.addArc(new RectF(bubbleRect.right-(2*margin), bubbleRect.top,bubbleRect.right,bubbleRect.top+(2*margin)),270,90f);
            outlinePath.moveTo(bubbleRect.right,bubbleRect.top+margin);
            outlinePath.lineTo(bubbleRect.right,bubbleRect.bottom-margin);
            outlinePath.addArc(new RectF(bubbleRect.right-(2*margin), bubbleRect.bottom-(2*margin),bubbleRect.right,bubbleRect.bottom),0,90f);
            outlinePath.moveTo(bubbleRect.right-margin,bubbleRect.bottom);
            outlinePath.lineTo((3.0f/4.0f)*bubbleRect.width()+bubbleRect.left,bubbleRect.bottom);
            outlinePath.lineTo(position.x, position.y);
            outlinePath.lineTo(position.x,bubbleRect.bottom);
            outlinePath.lineTo(bubbleRect.left+margin, bubbleRect.bottom);
            outlinePath.addArc(new RectF(bubbleRect.left, bubbleRect.bottom-(2*margin),bubbleRect.left+(2*margin),bubbleRect.bottom),90,90f);
            outlinePath.moveTo(bubbleRect.left,bubbleRect.bottom-margin);
            outlinePath.lineTo(bubbleRect.left,bubbleRect.top+margin);
            outlinePath.moveTo(bubbleRect.left,bubbleRect.top);
            outlinePath.close();

代码成功绘制了我想要的形状并填充了一个小三角形,但是大部分形状没有填充。 (唯一被填充的部分是连续 2 个“lineTo”之间。

如何使用 addArc 并仍然填充形状?

【问题讨论】:

    标签: android canvas graphics path


    【解决方案1】:

    在调用 moveTo() 关闭前一部分之前添加对 outlinePath.close() 的调用

    【讨论】:

      猜你喜欢
      • 2016-04-16
      • 2018-03-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      相关资源
      最近更新 更多