视图的边距和填充之间的区别是什么?
当前回答
边距在视图内,边距在视图外。填充可用于所有视图。根据视图的不同,边距和边距之间可能存在或可能没有视觉差异。
例如,对于按钮,特征按钮背景图像包括填充,但不包括空白。换句话说,添加更多的填充会使按钮在视觉上看起来更大,而添加更多的边距只会使按钮和下一个控件之间的距离更宽。
另一方面,对于TextViews,填充和边缘的视觉效果是相同的。
页边距是否可用是由视图的容器决定的,而不是视图本身。在LinearLayout中支持边距,在AbsoluteLayout(现在已经过时了)中不支持边距。
其他回答
填充在视图内部。
边距在视图之外。
这种差异可能与背景或大小属性有关。
填充 填充在视图内部。例如,如果你给android:paddingLeft=20dp,那么视图内的项目将以20dp宽度从左排列。你也可以使用paddingRight, paddingBottom, paddingTop分别从右边,底部和顶部给出填充。
保证金 边距在视图之外。例如,如果你给android:marginLeft=20dp,那么视图将从左起20dp后排列。
简单地说: 填充改变盒子的大小(用一些东西)。 边距改变不同框之间的间距
为了帮助我记住填充物的含义,我想到了一件有很多厚棉质填充物的大外套。我在我的外套里,但是我和我的棉袄在一起。我们是一个整体。
但为了记住空白,我会想,“嘿,给我一些空白!”那是我和你之间的空白。不要进入我的舒适区——我的底线。
为了让它更清楚,这里是一个图片的填充和空白在TextView:
上图的XML布局
<?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>
相关的
重力vs布局重力 Match_parent vs wrap_content
填充是指小部件和小部件原始框架之间的空间。但边际是小部件的原始框架之间的空间边界其他小部件的框架。
推荐文章
- 如何在android中获得当前前景活动上下文?
- 如何在Android中获取当前日期?
- 获取Android设备名称
- 在WebView中上传文件
- 加载HTML文件到WebView
- Android:为什么视图没有maxHeight ?
- 如何获得具有已知资源名称的资源id ?
- 在Android上将字符串转换为整数
- 为什么“System.out。”println“工作在Android?
- WebView显示err_cleartext_not_allowed尽管站点是HTTPS
- Android M权限:对shouldShowRequestPermissionRationale()函数的使用感到困惑
- 为什么构建类型与产品风味不同?
- 我如何在一个片段中访问getSupportFragmentManager() ?
- 调试在哪里。Android Studio中的密钥存储库
- 从资产中读取文件