简体   繁体   English

在Android中绘制椭圆形是可行的,但不能绘制矩形

[英]Drawing an Oval in Android works, but drawing a rectangle doesn't

I'm trying to use a RectF to drawOval() and then again to try and drawRect() . 我试图使用RectFdrawOval() ,然后再次尝试使用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. 我唯一的想法是,到目前为止,这种方法不起作用,是当终点位于起点之前时,drawRect不喜欢。

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. 我认为您需要处理这些要点,以使它们符合RectF。

From http://developer.android.com/reference/android/graphics/RectF.html 来自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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM