How to Draw Arrowline in android.graphics.Path with correct configerations

醉酒当歌 提交于 2019-12-11 22:21:58

问题


What I have Tried:

I'm trying to display the arrow line with following code

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)

I have got the following result

Problem:

I'm not able draw the required expected result, I'm failed to understand/find path configuration parameters for displaying following result! I'm failed to increase the length, width size of the arrow line.

Expected result:

any help will be grateful !


回答1:


you can use canvas.rotate() method to rotate arrow

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


来源:https://stackoverflow.com/questions/26292752/how-to-draw-arrowline-in-android-graphics-path-with-correct-configerations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!