0

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

enter image description here

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:

enter image description here

any help will be grateful !

LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
  • Have you tried replacing `mWidth` with `mHeight` and vice versa in your code? – Karakuri Oct 10 '14 at 05:57
  • Yes, I'm not good at graphics, I'm failed increase the length of the arrow tail. with specified configuration. – LOG_TAG Oct 10 '14 at 05:59
  • I can't use _canvas.drawPath(path, paint)_ used to draw the line like this http://stackoverflow.com/questions/6713757/how-do-i-draw-an-arrowhead-in-android – LOG_TAG Oct 10 '14 at 06:02

1 Answers1

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);
Nooh
  • 1,548
  • 13
  • 21
  • In this case I cant use canvas since I'm Using ShapeDrawable , I can use _Matrix_ for any shape rotation, I'm looking for the rifgt config to path for changing the arrow tail lenth. – LOG_TAG Oct 10 '14 at 06:12
  • 1
    i think its problem with your coordinates, try drawing in papper.@LOG_TAG – Nooh Oct 10 '14 at 06:18