Reputation: 1698
I am trying to draw a line, but I keep getting problems. I want to achieve something like this:
private Paint red = new Paint();
private Paint orange = new Paint();
red.setColor(Color.parseColor("#FF0000"));
orange.setColor(Color.parseColor("#FF8C00"));
canvas.drawRect(0, 400, 300, 0, red);
canvas.drawRect(300, 400, 300, 0, orange);
The orange bar just sits in the same spot as the red one... Why?
Upvotes: 1
Views: 283
Reputation: 77083
You have the top of 400 and the bottom of 0. It is strange. You might want to swap them. However, the problem is that your first line has a left bound of 0 and the right bound of 300, while the second line is an orange point, having the left bound of 300 and the right bound is exactly there, at 300.
Upvotes: 0
Reputation: 2424
Can you see that the length of the orange rectangle (300-300) is 0 in your code. That is why you can't see it. So try this:
canvas.drawRect(0, 400, 300, 0, red);
canvas.drawRect(300, 400, 600, 0, orange);
Upvotes: 1
Reputation: 12121
Take a look at the documentation again: Canvas.drawRect
drawRect(float left, float top, float right, float bottom, Paint paint)
Draw the specified Rect using the specified paint.
So your last two coordinate values (right
and bottom
) are NOT length but position.
Upvotes: 0