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

I want to get a drawing limit, but then I use the getBounds or copyBounds method. All of them return Rect (0, 0 - 0, 0). code like this

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

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

why? the token is NOT null and I have res tbar_single_pressed ....

THX

+6
source share
1 answer

Drawings have no dimensions unless they have been drawn. If you want to get the size of the image you are going through, you can create your own rectangle using drawable.getIntrinsicWidth() and drawable.getIntrinsicHeight()

+10
source

Source: https://habr.com/ru/post/914052/


All Articles