【问题标题】:about android Drawable getBounds return Rect(0, 0 - 0, 0)关于android Drawable getBounds return Rect(0, 0 - 0, 0)
【发布时间】:2012-04-24 16:36:27
【问题描述】:

我想获得可绘制的边界,但随后我使用 getBounds 或 copyBounds 方法。它们都返回 Rect(0, 0 - 0, 0)。 像这样的代码

    Drawable marker = getResources().getDrawable(
            R.drawable.tbar_single_pressed);
    Rect copyRect = marker.copyBounds();
    Rect getRect= marker.getBounds();

那么结果 copyRect 是 Rect(0, 0 - 0, 0) getRect 也是 Rect(0, 0 - 0, 0)

为什么?标记不为空,我有 res tbar_single_pressed....

谢谢

【问题讨论】:

    标签: android drawable


    【解决方案1】:

    除非已绘制,否则可绘制对象没有尺寸。如果你想得到你传入的图像的大小,你可以用drawable.getIntrinsicWidth()drawable.getIntrinsicHeight()创建你自己的矩形

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2016-01-25
      相关资源
      最近更新 更多