about android Drawable getBounds return Rect(0, 0 - 0, 0)

坚强是说给别人听的谎言 提交于 2019-12-19 07:10:33

问题


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();

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

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

thx


回答1:


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()



来源:https://stackoverflow.com/questions/10302163/about-android-drawable-getbounds-return-rect0-0-0-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!