Cri*_*ian 574
填充是边框内部,边框和实际视图内容之间的空间.请注意,填充完全围绕内容:顶部,底部,右侧和左侧有填充(可以是独立的).
边距是边框之外,边框和此视图旁边的其他元素之间的空格.在图像中,边距是整个对象外部的灰色区域.请注意,与填充一样,边距完全围绕内容:顶部,底部,右侧和左侧都有边距.
图像说超过1000个单词(从Margin Vs Padding中提取- CSS属性):
Sur*_*gch 548
为了帮助我记住填充物的含义,我想到了一件带有大量厚棉垫的大衣.我穿着外套,但是我和我的衬垫在一起.我们是一个单位.
但要记住保证金,我想," 嘿,给我一些余地! "这是我和你之间的空白.不要进入我的舒适区 - 我的保证金.
为了更清楚,这里是一个填充和边距的图片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="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#c5e1b0"
android:textColor="#000000"
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:textColor="#000000"
android:text="TextView margin only"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#c5e1b0"
android:padding="10dp"
android:textColor="#000000"
android:text="TextView padding only"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f6c0c0"
android:padding="10dp"
android:textColor="#000000"
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:textColor="#000000"
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:textColor="#000000"
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="#c5e1b0"
android:textColor="#000000"
android:text="TextView no padding no margin"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f6c0c0"
android:textColor="#000000"
android:text="TextView no padding no margin"
android:textSize="20sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Sev*_*yev 41
填充在视图内,边距在外面.填充适用于所有视图.根据视图,填充和边距之间可能存在或可能不存在视觉差异.
例如,对于按钮,特征按钮背景图像包括填充,但不包括边距.换句话说,添加更多填充使按钮看起来更大,而添加更多边距只会使按钮和下一个控件之间的间隙变宽.
TextView
另一方面,对于s,填充和边距的视觉效果是相同的.
边距是否可用取决于视图的容器,而不是视图本身.在LinearLayout
支持保证金,AbsoluteLayout
(现在已经过时) - 没有.
有时你只能通过填充或边距来实现相同的结果.示例:
假设视图X包含视图Y(又名:视图Y在视图X内).
- 使用Margin = 30查看Y或使用Padding = 30查看X将获得相同的结果:视图Y的偏移量为30.
小智 7
填充
的填充是View.For示例的内部,如果你给android:paddingLeft=20dp
,那么该视图内的物品将与安排20dp
从left.You宽度也可以使用paddingRight
,paddingBottom
,paddingTop
它们分别以得到由右,底部和顶部填充.
保证金
保证金在a View
.之外.例如,如果您给出android:marginLeft=20dp
,则视图20dp
将从左侧开始排列.
归档时间: |
|
查看次数: |
238189 次 |
最近记录: |