I'm just starting to learn android and i had a question regarding negative padding. How exactly does negative padding affect the view ?
Also, say I introduce a bottomPadding
of "-5dp". Does this extend of the boundary of the padding by 5dp ?
All help appreciated! :)
Padding only takes positive values. Negatives are ignored or treated as 0, which would have the same effect: none.
The downside of negative margins is they are difficult to debug and will make your CSS harder to read. The most often misuses of negative margins that I encounter is when it is used to make up for incorrect layouts elsewhere on the site. This is indeed bad practice.
Using negative margin is considered bad practice as it makes the code more complex and difficult for developer's understanding. Generally there is no need to use negative margin, unless and until you have made any error elsewhere.
It is possible to give margins a negative value. This allows you to draw the element closer to its top or left neighbour, or draw its right and bottom neighbour closer to it.
In LinearLayout
and RelativeLayout
after setting negative padding you will notice movement of the content into opposite direction - for example if you set paddingLeft
to -5dp, it will be moved to the left side by 5dp, whereas setting it to 5dp would cause content to be moved into right position.
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