• 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>

  • 相关阅读:
    cron表达式详解(转载)
    Swagger 3.0使用教程(转载)
    springboot整合shiro-对密码进行MD5并加盐处理(十五)(转载)
    redis排序
    引用和指针的区别?
    测试策略
    主键、外键的作用,索引的优点与不足?
    您所熟悉的软件测试类型都有哪些?请试着分别比较这些不同的测试类型的区别与联系(如功能测试、性能测试……)
    UI测试测什么
    数据库,数据库管理系统,数据库系统三者的区别和练习?
  • 原文地址:https://www.cnblogs.com/lavenderone/p/2179299.html
Copyright © 2020-2023  润新知