I am confused with setbounds method of drawable in Android. I know it is used with drawable and it set where drawable and how large it is. Briefly, it defines, bounding rectangle for drawable. But I am confused: does it set border or padding or its width or height?
This is how we use setbounds
drawableInstance.setBounds(L,T,R,B);
So in above case, If I set 5,5,5,5 for L,T,R,B respectively, L,T,R,B of drawable will be always from its parent respectively? I mean will it be like setting hidden 5px border to every side?Besides, if image is not large enough to meets that border width to its parent, will image be bigger?
I set 5,5,100,100 for L,T,R,B respectively. What I am confusing is, it will starts drawing from away from parent 5px to the top and 5px to the left. That will be the start point. Then image with will be 100px because I set 100 for right. So it goes to the right 100px. Same to bottom with right.
But I tested it. I think both is not as what I think. How does it work, especially in relation to each parameter of setBounds?
Classic drawable resources such as images are stored in the drawable folder. In contrast, vector drawables are stored in drawable-v24 . For this project, keep the drawable default and click OK. You should now see the New File dialog box.
Drawable. invalidateSelf() will call the view's invalidateDrawable() method, which will invalidate only the current bounds of the drawable. If you aren't moving the drawable around, this will have the same effect as calling invalidate(mDrawable. getBounds()) .
Once you import svg file into Android Studio project, you are going to see <vector> resource then just change the size as you want by width , height attributes. viewportWidth and viewportHeight is to set size for drawing on virtual canvas.
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.
The bounds values are absolute, not relative. That is, width == right - left
, and height == bottom - top
.
Your first example will have the top left corner of the Drawable
at (5, 5)
, but the width and height will both be 0
.
The second example will also have the top left corner at (5, 5)
, and the width and height will both be 95
.
The bounds are not dependent on the dimensions of the Canvas
to which the Drawable
is drawn. For instance, if you draw a Drawable
with the bounds of your second example onto a View
that is only 50
by 50
, its left and top sides will be inset by 5
, but it will get cut off at the right and bottom borders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With