如何使用正确的配置在android.graphics.Path中绘制箭头线

时间:2014-10-10 05:52:32

标签: android android-canvas android-view android-shape

我尝试了什么:

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

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)

我得到以下结果

enter image description here

问题:

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

预期结果:

enter image description here

任何帮助都将不胜感激!

1 个答案:

答案 0 :(得分:1)

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

OR

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);