zoukankan      html  css  js  c++  java
  • padding margin 的区别

    padding是站在父view的角度描述问题,它规定它里面的内容必须与这个父view边界的距离。margin则是站在自己的角度描述问题,规定自己和其他(上下左右)的view之间的距离,如果同一级只有一个view,那么它的效果基本上就和padding一样了。

    match_parent(相对与父类组件)

    wrap_content(包裹内容)

    fill_parent(填充父类组件)

    例如我的XML layout代码如下:


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="10dip"
        android:paddingRight="10dip"
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        >
    <TextView 
        android:background="#FF0000"
        android:text="string/hello"
        android:paddingLeft="50dip"
        android:paddingRight="50dip"
        android:paddingTop="50dip"
        android:paddingBottom="50dip"
         android:layout_marginBottom="10dip"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:gravity="center"
        android:layout_marginLeft="50dip"
        />
        <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="@string/hello"
        android:paddingLeft="50dip"
        android:paddingRight="50dip"
        android:paddingTop="50dip"
        android:paddingBottom="50dip"
          android:layout_marginBottom="10dip"
        />
        <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="@string/hello"
        android:paddingLeft="50dip"
        android:paddingRight="50dip"
        android:paddingTop="50dip"
        android:paddingBottom="50dip"
        android:layout_marginBottom="10dip"
        />
        <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="@string/hello"
        android:paddingLeft="50dip"
        android:paddingRight="50dip"
        android:paddingTop="50dip"
        android:paddingBottom="50dip"
        android:layout_marginBottom="10dip"
        />
    </LinearLayout>

  • 相关阅读:
    io系列浅谈
    git 删除分支--本地分支和远程分支
    提问须知
    PDF 补丁丁 0.6.2.3691 测试版发布
    PDF 补丁丁 0.6.2.3689 测试版发布
    .Net调用接口处理时间过长,前端访问超时解决方案
    Abp用多个DbContext
    IDEA 报错 Could not autowire. No beans of 'UserMapper' type found(无法自动装配。找不到类型为 'UserMapper' 的 bean)解决IDEA中自动装配,找不到类型的bean问题
    springboot整合springmvc拦截器
    springboot自动配置原理
  • 原文地址:https://www.cnblogs.com/lavenderone/p/2179299.html
Copyright © 2011-2022 走看看