关于Android的getBounds可绘制矩形返回(0,0 - 0,0) [英] about android Drawable getBounds return Rect(0, 0 - 0, 0)

查看:2756
本文介绍了关于Android的getBounds可绘制矩形返回(0,0 - 0,0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的约束绘制后来我用​​的getBounds或copyBounds方法。他们都返回矩形(0,0 - 0,0)。
 在code这样的

i want get the bound of drawable but then i use getBounds or copyBounds method .they all return Rect(0, 0 - 0, 0). the code like this

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

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

then the result copyRect is Rect(0, 0 - 0, 0) getRect is also Rect(0, 0 - 0, 0)

为什么?标记为NOT NULL和我有资源tbar_single_ pressed ....

why? the marker is NOT null and i have the res tbar_single_pressed....

THX

推荐答案

可绘制没有尺寸,除非他们已经被绘制。如果你想获得你传递的图像的大小,你可以创建自己的矩形与 drawable.getIntrinsicWidth()绘制。 getIntrinsicHeight()

Drawables don't have dimensions unless they've been drawn. If you want to get the size of the image you're passing in, you can create your own rect with drawable.getIntrinsicWidth() and drawable.getIntrinsicHeight()

这篇关于关于Android的getBounds可绘制矩形返回(0,0 - 0,0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆