The difference between padding and margin

Source: Internet
Author: User

The difference between android:padding and Android:layout_margin has not been understood before, in fact the concept is very easy,padding to describe the narrative in the perspective of the parent view, which specifies that its contents must be within the bounds of the parent view. Margin is to stand in their own perspective to describe the narrative problem, and other (up and down) the distance between the view, assuming that the same level only has a view, then its effect is basically the same as padding. For example, my XML layout code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " android:paddingleft= "10dip" android:paddingright= "10dip" android:paddingtop= "10dip" android:paddingbottom= "10dip "><textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content "ANDROID:BACKGR" Ound= "#FF0000" android:text= "@string/hello" android:paddingleft= "50dip" android:paddingright= "50dip" android:p addingtop= "50dip" android:paddingbottom= "50dip" android:layout_marginbottom= "10dip"/> <textview androi D:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:background= "#FF0000" android:text= "@ String/hello "android:paddingleft=" 50dip "android:paddingright=" 50dip "android:paddingtop=" 50dip "Android:padd Ingbottom= "50dip" Android:layout_marginbottom= "10dip"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_conte NT "android:background=" #FF0000 "android:text=" @string/hello "android:paddingleft=" 50dip "Android:paddingrigh t= "50dip" android:paddingtop= "50dip" android:paddingbottom= "50dip" android:layout_marginbottom= "10dip"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:background= "# FF0000 "android:text=" @string/hello "android:paddingleft=" 50dip "android:paddingright=" 50dip "Android:paddingt op= "50dip" android:paddingbottom= "50dip" android:layout_marginbottom= "10dip"/></linearlayout>Then I will get such as the following effect, the figure has been very clear the mark out of the difference.

The difference between padding and margin

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.