0

我试过的:

我正在尝试使用以下代码显示箭头线

Path mArrowPath=new Paint();;
mArrowPath.rewind();
mArrowPath.moveTo(0, mHeight / 2);
mArrowPath.lineTo(mWidth / 2, 0);
mArrowPath.lineTo(mWidth, mHeight / 2);
mArrowPath.lineTo(mWidth * 3 / 4, mHeight / 2);
mArrowPath.lineTo(mWidth * 3 / 4, mHeight);
mArrowPath.lineTo(mWidth / 4, mHeight);
mArrowPath.lineTo(mWidth / 4, mHeight / 2);
mArrowPath.lineTo(0, mHeight / 2);

Shape pathshap = new PathShape(mArrowP,maxWidth,maxHeight);

ShapeDrawable shapeD = new ShapeDrawable(pathshap);

shapeD.draw(canvas); //display it in onDraw(Canvas canvas)

我得到了以下结果

在此处输入图像描述

问题:

我无法绘制所需的预期结果,我无法理解/找到用于显示以下结果的路径配置参数!我未能增加箭头线的长度宽度大小。

预期结果:

在此处输入图像描述

任何帮助将不胜感激!

4

1 回答 1

1

你可以使用 canvas.rotate() 方法来旋转箭头

或者

Path mArrowPath=new Paint();;
mArrowPath.rewind();
mArrowPath.moveTo(mWidth , mHeight / 2);
mArrowPath.lineTo(mWidth / 2, mHeight );
mArrowPath.lineTo(mWidth / 2, mHeight* 3 / 4);
mArrowPath.lineTo(0, mHeight* 3 / 4);
mArrowPath.lineTo(0, mHeight/ 4);
mArrowPath.lineTo(mWidth / 2, mHeight/ 4);
mArrowPath.lineTo(mWidth / 2,0);
mArrowPath.lineTo(mWidth , mHeight / 2);
Shape pathshap = new PathShape(mArrowP,maxWidth,maxHeight);

ShapeDrawable shapeD = new ShapeDrawable(pathshap);

shapeD.draw(canvas);
于 2014-10-10T06:05:36.580 回答