Understanding of padding and margin in Android

Source: Internet
Author: User

Padding and margin are often used when arranging control layouts on Android.

Its specific explanation can be shown by a graph, as below,

Two properties represent the same meaning as Web programming.

Deep Understanding:

Padding constrains the distance the control or layout displays from the bounding rectangle, compressing it inward along the vertical border, and the larger the padding, the smaller the content display control;

Margin this is the distance extending outward along the vertical border, which means to add a certain distance to the control of the blank edge, the display effect only with the value of positive and negative correlation, and other element bounds independent.

It is worth noting that the range of the padding value [0, any positive number] (the default is 0), and the value of margin has a positive negative.

To understand negative values, the first thing to understand is the 0 value, when the margin= "0dip", the control extension of the edge is 0, that is, the boundary next to the other edge;

Margin>0, is to add white edge to the control, so that its extension becomes larger, when too large will affect the entire control display size;

Margin<0, typically used in a single-direction display, that is, the distance between the control and its neighboring controls is negative, from the display is to overwrite the other controls in one direction.

In general, these two properties are properties of a control that control only the display of the control, the meaning of which is also not involved in the parent control or other neighboring controls, so be aware of, do not confuse.

start and end are the relative concepts of change, as follows,
    1. Paddingstart & Paddingend Works according to the right and left alignment (level-api-17 )
    2. When left aligned, Paddingstart corresponds to Paddingleft, paddingend corresponds to Paddingright
    3. Right-aligned, just the opposite

The above personal understanding, reproduced annotated source, thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.