赞
踩
① android : padding
padding 英 ['pædɪŋ] 美 ['pædɪŋ] n.垫充;垫塞;填料;废话;
android : padding : 为内边框,指该控件内部内容,如文本/图片距离该控件的边距。
② android : margin
margin 英 ['mɑːdʒɪn] 美 ['mɑrdʒən] n. 旁注
android : margin : 为外边框,指该控件距离边父控件的边距
padding 和 margin 都是指代距离;
控件中的内容与控件之间的距离称为内边距 ----- padding 即填充;
其针对的是组件中的元素,即设置组件内部元素之间的边距;
往内部元素的左边填充 20 个边距为:paddingLeft = “20dp”控件和控件之间的距离称为外边距 ----- margin 即边界;
其针对的是容器中的组件,即设置组件与父容器之间的边距(偏移);
设置组件离左边偏移 20 个边距为:marginLeft = “20dp”注:如果上下左右(Top、Bottom、Left、Right)的距离都是相同的直接写 padding 或 margin 属性进行设置,否则无效。
margin 是外边距,即盒子与盒子之间的距离,
padding 是内边距,是盒子的边与盒子内部元素的距离。margin 是用来隔开元素与元素的间距;
padding 是用来隔开元素与内容的间隔。margin 使元素与元素互不相干;
padding 让内容(文字)与(包裹)元素之间有一段“呼吸距离”。
如下设置了两个 TextView 控件,然后我们设置了其外边距以及内边距的大小,如果两个控件都设置了外边距,那么它们之间的距离就是两个边距之和
<?xml version="1.0" encoding="utf-8"?> <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="match_parent" android:layout_height="wrap_content" android:background="#ABCDEF" android:layout_margin="60dp" android:paddingLeft="40dp" android:text="Hello World"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="90dp" android:textSize="30sp" android:background="#FEDCBA" android:padding="60dp" android:text="Hello World GuYu"/> </LinearLayout>
Note:
欢迎点赞,留言,转载请在文章页面明显位置给出原文链接
知者,感谢您在茫茫人海中阅读了我的文章
没有个性 哪来的签名!
详情请关注点我
持续更新中
© 2022 08 - Guyu.com | 【版权所有 侵权必究】 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。