将Rect转换为RectF

时间:2013-12-18 23:17:50

标签: android android-canvas rectangles

将Rect变量转换为RectF变量的最佳方法是什么?我无法施展它。

RectF rect = (RectF) currentRect; //produces an error

2 个答案:

答案 0 :(得分:17)

RectF rect = new RectF(currentRect);

答案 1 :(得分:1)

“不应在onDraw中完成”

// As class fields,
Rect rect = new Rect();
RectF rectF = new RectF();

...
onDraw(Canvas canvas) {
    ...
    rectF.set(rect);
    ...
}