Difference between margin and padding

Source: Internet
Author: User

In Android layout development, margin and padding are very common attributes.

The two are spacing, but they are different. Let's make a record.

 

Margin: the outer spacing. For example, if we have a button that is thrown to the linear layout, we set margin to indicate the distance between the button and the screen.

 

Padding: padding. Take this buttton as an example. Think about it. The gravity of the button has left, right, horizontal, and vertical center. But what if we want to center the text in the button vertically to the right? You can use padding. First, we set the button to vertical center, and then set paddingleft = "50dp" (the value here depends on the resolution of your screen, it refers to the spacing between the text and the border inside the button.

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.