• app简单控件了解——视图——设置视图的间距





    <!-- 最外层的布局背景为蓝色 -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="#00aaff"
        android:orientation="vertical"
        android:padding="5dp">
    
        <!-- 中间层的布局背景为黄色 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:background="#ffff99"
            android:padding="60dp">
    
            <!-- 最内层的视图背景为红色 -->
            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#ff0000" />
        </LinearLayout>
    </LinearLayout>






    ============================================================================================





    android:layout_marginTop="30dp" -----该属性的作用是让当前视图与上方间隔一段距离


    android:layout_marginBottom="30dp"-----该属性的作用是让当前视图与下方间隔一段距离
    
    
    android:layout_marginLeft="30dp"-----该属性的作用是让当前视图与左边间隔一段距离


    android:layout_marginRight="30dp"-----该属性的作用是让当前视图与右边间隔一段距离




    示例:

    <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_marginTop="5dp"
            android:background="#00ffff"
            android:text="视图宽度采用wrap_content定义"
            android:textColor="#000000"
            android:layout_marginLeft="30dp"
            android:textSize="17sp" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#00ffff"
            android:text="视图宽度采用match_parent定义"
            android:textColor="#000000"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginBottom="30dp"
            android:layout_marginTop="30dp"
            android:textSize="17sp" />
    
        <TextView
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:background="#00ffff"
            android:text="视图宽度采用固定大小"
            android:textColor="#000000"
            android:textSize="17sp" />
    
        <TextView
            android:id="@+id/tv_code"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:background="#00ffff"
            android:text="通过代码指定视图宽度"
            android:textColor="#000000"
            android:textSize="17sp" />
    </LinearLayout>

     




    如果上下左右都要间隔同样的具体,还能使用 android:layout_margin="60dp" 设置
    
    
    <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_marginTop="5dp"
            android:background="#00ffff"
            android:text="视图宽度采用wrap_content定义"
            android:textColor="#000000"
            android:layout_marginLeft="30dp"
            android:textSize="17sp" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#00ffff"
            android:text="视图宽度采用match_parent定义"
            android:textColor="#000000"
            android:layout_margin="60dp"
            android:textSize="17sp" />
    
        <TextView
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:background="#00ffff"
            android:text="视图宽度采用固定大小"
            android:textColor="#000000"
            android:textSize="17sp" />
    
        <TextView
            android:id="@+id/tv_code"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:background="#00ffff"
            android:text="通过代码指定视图宽度"
            android:textColor="#000000"
            android:textSize="17sp" />
    </LinearLayout>


    =======================================================================

    android:layout_margin指的是当前视图与外部视图(包括上级视图和平级视图)之间的间距。


    android:padding指的是当前视图与内部视图(包括下级视图和内部文本之间的距离)
    android:padding也提供了4个方向的距离属性:

    <!-- 最外层的布局背景为蓝色 -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="#00aaff"
        android:orientation="vertical">
    
        <!-- 中间层的布局背景为黄色 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:background="#ffff99"
            android:padding="60dp">
    
            <!-- 最内层的视图背景为红色 -->
            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#ff0000" />
        </LinearLayout>
    </LinearLayout>

     

    --------------------------------------------------------------------------------------------------------------------------

    PS:

    如果去除此属性:

    <!-- 最外层的布局背景为蓝色 -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="#00aaff"
        android:orientation="vertical">
    
        <!-- 中间层的布局背景为黄色 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:background="#ffff99">
    
            <!-- 最内层的视图背景为红色 -->
            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#ff0000" />
        </LinearLayout>
    </LinearLayout>

     

    --------------------------------------------------------------------------------

    PS:

    设置如下属性:

    android:paddingBottom="60dp"
    android:paddingLeft="10dp"
    <!-- 最外层的布局背景为蓝色 -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="#00aaff"
        android:orientation="vertical">
    
        <!-- 中间层的布局背景为黄色 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:background="#ffff99"
            android:paddingBottom="60dp"
            android:paddingLeft="10dp">
    
            <!-- 最内层的视图背景为红色 -->
            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#ff0000" />
        </LinearLayout>
    </LinearLayout>

     

    ======================================================================

     

     

     

  • 相关阅读:
    Oracle SQL性能优化
    spring aop简单日志实例
    一个简单的Spring AOP例子
    jQuery的三种$()
    Mac 上的 outlook 一直让输入密码
    idea 中设置成公司规范的代码格式
    Java 中的锁——Lock接口
    TimeUnit枚举类
    Thread.join()的使用
    java线程的等待、通知机制【读书笔记】
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/16414668.html
Copyright © 2020-2023  润新知