Problem with adding Android

:) I had the following problem: I have a view, and I want to add borders to it. What I'm trying to do now is install an addition to the view (padding on all sides) and set the background color for it to fill the fill. The fact is that it seems to me that you can set indents only from above and to the left or from below and to the right, but not from all together. I. If I write

view.setPadding(border,border,border,border)

this will only fill at the top and left. To set the registration bottom and right, I have to write:

view.setPadding(-border,-border,0,0)

which will not leave left and top margins, etc. If I try to use margin, it moves the whole block (view + fill area), but not just the view, so this also does not work. Any ideas on how to do this without using a packaging layout? Thank!

+5
source share
2 answers

What exactly happens when you use the first example?

The four parameters intfor setPadding()relate to the left, top, right, and bottom, respectively. So the call setPadding(4, 5, 6, 7)should give you 4 pixels of space for the left edge, 5 for the top, 6 for the right and 7 for the bottom. What result do you get when you do this? Can you show a screenshot?

+3
source

What is the content of your submission? If this image or something similar, it may not be centered or scaled properly. Try calling setGravity(CENTER);.

+2
source

All Articles