视图的填充和边距之间的区别

拟墨画扇 提交于 2020-01-10 10:50:33

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

视图的边距和填充之间有什么区别?


#1楼

填充是边界与实际图像或单元格内容之间的边界内的空间。 边界是边界外部,边界与该对象旁边的其他元素之间的空间。


#2楼

有时,您可以通过仅使用填充或边距来获得相同的结果。 范例:

说视图X包含视图Y(又名:视图Y在视图X内)。

-边距= 30的视图Y或填充= 30的视图X将获得相同的结果:视图Y的偏移量为30。


#3楼

为了帮助我记住衬垫的含义,我想起一件大外套,上面有很多厚的棉衬垫 。 我在外套里,但是我和我的棉coat在一起。 我们是一个单位。

但是要记住余量 ,我想到:“ 嘿,给我一些余量! ”这是我和您之间的空白。 不要进入我的舒适区-我的边缘。

为了更加清楚,这是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>

有关


#4楼

假设您在视图中有一个按钮,并且视图的大小为200 x 200,按钮的大小为50 x 50,按钮标题为HT。 现在margin和padding的区别是,您可以在视图中设置按钮的margin,例如从左边20,从顶部20,并且padding会调整按钮或文本视图中的文本位置等。 ,填充值从左侧开始为20,因此它将调整文本的位置。


#5楼

下图将让您了解填充和边距-

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!