Вопрос

I'm trying to use a RectF to drawOval() and then again to try and drawRect(). The oval shows up, but the rectangle does not.

//onDraw
RectF rectF = new RectF(300, 300, 100, 100);
canvas.drawRect(rectF, paint); //doesn't display
canvas.drawOval(rectF, paint); //displays

Simple question, but I have no idea why it wouldn't want to draw this shape. My only idea is that this not working so far is that drawRect doesn't like when the end points are "before" the starting points.

EDIT: If I switch the numbers is works, but I need it to be able to accept any numbers, since in my actual application the numbers are dynamically input from the touch point of the user.

//onDraw
RectF rectF = new RectF(100, 100, 300, 300); //switched the coordinates
canvas.drawRect(rectF, paint); //displays
canvas.drawOval(rectF, paint); //displays
Это было полезно?

Решение

I think you need to handle the points so that they conform to RectF.

From http://developer.android.com/reference/android/graphics/RectF.html

Note: most methods do not check to see that the coordinates are sorted correctly (i.e. left <= right and top <= bottom).
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top