Android – Drawing an arrow in android

androidandroid-layoutshapes

Possible Duplicate:
How do I draw an arrowhead (in Android)?

I am trying to make a nice layout layout in android and for that I would like to connect two views with an arrow, which looks pretty much like this:

a busy cat

So on the start of the arrow there is supposed to be a view, and at the tip of the arrow as well.

Whats the best way to achieve this? Is the easiest just to use an image? But then I could not change the color of the arrow in android for example. Can I somehow do that with shapes?

Thank you!

Best Answer

You can use Canvas, and create your own "Arrow" view, its not too dificult, just drawLines using the right coordinates, or create a Path.

Extend View class, and override onDraw(Canvas c), then you should paint your lines with

Paint paint = new Paint();

....

public void onDraw(Canvas c){
            Path path = new Path();
            path.setFillType(Path.FillType.EVEN_ODD);
            path.moveTo(insideRectangleOffset, getHeight() - insideRectangleOffset);
            path.lineTo(getWidth() - insideRectangleOffset, insideRectangleOffset);
            path.lineTo(getWidth() - insideRectangleOffset, getHeight() - insideRectangleOffset);
            path.lineTo(insideRectangleOffset, getHeight() - insideRectangleOffset);
            path.close();

            c.drawPath(path, paint);
}

Replace the coordinates as your need, I've copy pasted the code from a view that I've created