视图的边距和填充之间的区别是什么?
当前回答
填充是指小部件和小部件原始框架之间的空间。但边际是小部件的原始框架之间的空间边界其他小部件的框架。
其他回答
下面的图片将让你了解填充和空白-
除了上述所有正确答案之外,另一个区别是填充增加了视图的可点击区域,而边距则不会。如果你有一个小的可点击图像,但想让点击处理程序宽容,这是有用的。
例如,看到我的ImageView布局的这张图片(Android图标),我将paddingbutton设置为100dp(图像是股票启动器mipmap ic_launcher)。有了附加的点击处理程序,我能够点击外面和下面的图像,仍然注册一个点击。
为了帮助我记住填充物的含义,我想到了一件有很多厚棉质填充物的大外套。我在我的外套里,但是我和我的棉袄在一起。我们是一个整体。
但为了记住空白,我会想,“嘿,给我一些空白!”那是我和你之间的空白。不要进入我的舒适区——我的底线。
为了让它更清楚,这里是一个图片的填充和空白在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:padding="15dp"来设置15dp所有边的填充
android:layout_margin="15dp"用于设置15dp所有边距
支持具体价值观:
填充
android:paddingBottom设置底部边缘的填充 android:paddingStart设置填充在开始边缘意味着在视图的左侧 android:paddingEnd设置填充在结束边缘意味着在右侧的视图 android:paddingTop设置顶部边距
保证金
layout_marginBottom在这个视图的底部指定额外的空间。 android:layout_marginEnd在结束端指定额外的空间,意味着在这个视图的右边。 android:layout_marginStart在开始侧指定额外的空间,意味着在这个视图的左边。 android:layout_marginTop在这个视图的顶部指定额外的空间。
推荐文章
- 如何在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中的密钥存储库
- 从资产中读取文件