Difference
The padding is inside the control
Margin is the outside of the control
, the Red line area is margin, the black area is padding
The following are the effects of TextView's various Padding,margin
It's all wrap_content.
<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android" Android:layout_width="Match_parent"android:layout_height="Match_parent" Android:orientation="vertical" > <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margin = "10DP" android:background = "#c5e1b0" android:text = " TextView margin only " android:textsize =" 20SP " /> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margin = "10DP" android:background = "#f6c0c0" android:text = " TextView margin only " android:textsize =" 20SP " /> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:background =< Span class= "Hljs-value" > "#c5e1b0" android:padding =" 10DP " android:text =" TextView padding only " android:textsize =" 20SP " /> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:background =< Span class= "Hljs-value" > "#f6c0c0" android:padding =" 10DP " android:text =" TextView padding only " android:textsize =" 20SP " /> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margin = "10DP" android:background = "#c5e1b0" android:padding = "10DP" android:text = "TextView padding and margin"
android:textsize
= "20sp" /> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margin = "10DP" android:background = "#f6c0c0" android:padding = "10DP" android:text = "TextView padding and margin"
android:textsize
= "20sp" /> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:background =< Span class= "Hljs-value" > "#c5e1b0" android:text =" TextView no padding no margin " android:textsize =" 20SP "/> <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" android:background="#f6c0c0"android:text="TextView no padding no margin" Android:textsize="20sp" /> </linearlayout>
Wide and high fixed size
<linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" android:layout_width =" match_parent " android:layout_height =" match_parent " android:orientation =; <textview android:layout _width = "350DP" android:layout_height = "50DP" android:layout_margin =" 10DP " android:background =" # C5e1b0 " android:text =" TextView margin only "
android:textsize = "20sp" /> <textview android:layout _width = "350DP" android:layout_height = "50DP" android:layout_margin =" 10DP " android:background =" # F6c0c0 " android:text =" TextView margin only "
android:textsize = "20sp" /> <textview android:layout _width = "350DP" android:layout_height = "50DP" android:background =" #c5e1b0 " android:padding =" 10DP " android:text =" TextView padding only " android:textsize = "20sp" /> <textview android:layout _width = "350DP" android:layout_height = "50DP" android:background =" #f6c0c0 " android:padding =" 10DP " android:text =" TextView padding only " android:textsize = "20sp" /> <textview android:layout _width = "350DP" android:layout_height = "50DP" android:layout_margin =" 10DP " android:background =" # C5e1b0 " android:padding =" 10DP " android:text = "TextView padding and margin" android:textsize = "20sp" /> <textview android:layout _width = "350DP" android:layout_height = "50DP" android:layout_margin =" 10DP " android:background =" # F6c0c0 " android:padding =" 10DP " android:text = "TextView padding and margin" android:textsize = "20sp" /> <textview android:layout _width = "350DP" android:layout_height = "50DP" android:background =" #c5e1b0 " android:text =" TextView no padding no margin " android:textsize = "20sp" /> <TextViewandroid:layout_width= "350dp"android:layout_height=" 50DP "android:background=" #f6c0c0 "android:text=" TextView no padding no margin " android:textsize="20sp" /> </linearlayout>
Contrast effects, and code. The difference should be seen by everyone.
The difference between padding and margin in Android