【问题标题】:Convert Rect to RectF将 Rect 转换为 RectF
【发布时间】:2013-12-18 23:17:49
【问题描述】:

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

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

【问题讨论】:

标签: android android-canvas rectangles


【解决方案1】:
RectF rect = new RectF(currentRect);

【讨论】:

    【解决方案2】:

    由于“新”不应该在 onDraw 中完成,

    // As class fields,
    Rect rect = new Rect();
    RectF rectF = new RectF();
    
    ...
    onDraw(Canvas canvas) {
        ...
        rectF.set(rect);
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 2014-05-07
      • 2011-05-14
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      相关资源
      最近更新 更多