1

我正在尝试绘制一条虚线作为ListView分隔项的分隔符,如下所示: 在此处输入图像描述

为了做到这一点,在其中一种情况下,我重写了该OnDraw()方法并使用了:

paint.SetPathEffect(new DashPathEffect(new[] { 2f, 2f }, 0));

_paint.StrokeWidth = 2;

使用DashPathEffectdows 绘制小点 - 但它们不是点 - 它们是小方块而不是圆点:

在此处输入图像描述

该应用程序是在 Xamarin 的框架上使用 monodroid 构建的

有什么想法吗?

4

2 回答 2

3

设置油漆

 mPaint.setStyle(Paint.Style.STROKE);
 mPaint.setStrokeWidth(30);
 mPaint.setPathEffect(new DashPathEffect(new float[]{1, 60}, 0f));
 mPaint.setStrokeCap(Paint.Cap.ROUND);

使用示例

canvas.drawPath(mPath, mPaint);

更新

还有另一种方法。在这里你可以设置任何形状

    paintBlue = new Paint(Paint.ANTI_ALIAS_FLAG);
    float mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, context.getResources().getDisplayMetrics());
    paintBlue.setStyle(Paint.Style.STROKE);
    paintBlue.setAntiAlias(true);
    paintBlue.setColor(Color.BLACK);
    paintBlue.setStrokeWidth(12);
    Path shapePath = new Path();
    shapePath.addCircle(0, 0, mRadius, Path.Direction.CCW);
    PathDashPathEffect pathDashPathEffect = new PathDashPathEffect(shapePath, mRadius * 4, 0, PathDashPathEffect.Style.ROTATE);
    paintBlue.setPathEffect(pathDashPathEffect);
于 2015-01-19T14:43:23.877 回答
1

If you are testing on device with API level>=11 then try setting layer type to LAYER_TYPE_SOFTWARE

于 2013-10-08T12:34:31.620 回答