Android canvas draw order

324 views Asked by At

I want to draw a border around my circle drawable.

I have this code:

  public void draw(Canvas canvas) {
    myDrawable.draw(canvas);
    canvas.drawArc(toHighlightBounds, 0F, 360F, /* useCenter= */ false, borderPaint);
}

How come the output is similar if I change the lines order?

  public void draw(Canvas canvas) {
    canvas.drawArc(toHighlightBounds, 0F, 360F, /* useCenter= */ false, borderPaint);
    myDrawable.draw(canvas);
}

Shouldn't the order dictates the z-axis? What is drawn above the other?

1

There are 1 answers

0
Jules Hummelink On

I don't know for sure but I think it has something to do with the way variables work.

For example, Let's say I make a data class with a drawable in it.

I then set the drawable to an image view

myImageView.setImageDrawable(myClassObject.drawable)

Here come's the funny part, if I now change the drawable of my object to something else, it will also change in the image view.

Im not sure if this is it and if it is an easy explanation but this is my guess