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>

  • 相关阅读:
    eclipse 使用 maven 无法编译 jsp 文件的问题
    iOS开发-Quartz2D绘制时定时器选择
    iOSUI-事件处理
    iOS开发-数据存储
    iOSUI-UIScrollView属性,方法大全
    iOSUI-UITableView属性,方法大全
    iOS网络-NSURLSession/AFNetworking发送HTTPS网络请求
    iOS网络-AFNetworking检测网络状态
    iOS网络-AFNetworking序列化
    iOS网络-AFNetworking基本使用,文件下载,上传
  • 原文地址:https://www.cnblogs.com/lavenderone/p/2179299.html
Copyright © 2011-2022 走看看