xml布局内容总结(二)--Android

关于xml中margin和padding的内容,在刚接触xml的时候会有些混淆和模糊,在此进行总结,希望能帮助到有需要的人。

2.xml中margin和padding

<?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:layout_margin="10dp"                              //当上下左右四个方向的边距一致时,可以使用这个统一设置

android:background="@color/red"

android:orientation="vertical" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/yellow"

android:layout_marginLeft="5dp"                       //当上下左右四个方向的边距不一致时,可以分别进行设置

android:layout_marginTop="15dp"

android:layout_marginRight="25dp"

android:layout_marginBottom="35dp"

android:orientation="vertical" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_margin="15dp"                                  //这是外边框

android:padding="35dp"                                             //这是内边框,内边框的四个方向一致时,可以统一设置

android:background="@color/blue"

android:orientation="vertical" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/gray"

android:paddingLeft="5dp"                              //内边框的四个方向不一致时,可以分别进行设置

android:paddingTop="15dp"

android:paddingRight="25dp"

android:paddingBottom="35dp"

android:orientation="vertical" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/green"

android:orientation="vertical" >

</LinearLayout>

</LinearLayout>

</LinearLayout>

</LinearLayout>

</LinearLayout>

效果图如下:

通过效果图和xml中的设置应该很快可以掌握margin和padding的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-08 00:00:09

xml布局内容总结(二)--Android的相关文章

xml布局内容总结(四)--Android

(1)对于xml编写界面较复杂的情况下,使用include会使得编写和查看更清楚 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <include android:id="@+id/hi1" layout="@

xml布局内容总结(三)--Android

关于xml中经经常使用到边框及边框效果,在此进行一下总结. 3.border(边框及边框效果) (1)直角边框线 <LinearLayout android:layout_width="200dp" android:layout_height="30dp" android:layout_margin="10dp" android:orientation="vertical" android:background=&quo

Android 布局学习之——Layout(布局)具体解释二(常见布局和布局參数)

 [Android布局学习系列]   1.Android 布局学习之--Layout(布局)具体解释一   2.Android 布局学习之--Layout(布局)具体解释二(常见布局和布局參数)   3.Android 布局学习之--LinearLayout的layout_weight属性   4.Android 布局学习之--LinearLayout属性baselineAligned的作用及baseline    Layout Parameters(布局參数): 在XML文件里,我们常常看到类

Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)

[Android布局学习系列]   1.Android 布局学习之——Layout(布局)详解一   2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)   3.Android 布局学习之——LinearLayout的layout_weight属性   4.Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline    Layout Parameters(布局参数): 在XML文件中,我们经常看到类似与lay

Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析

转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PARENT/FILL_PARENT属性的原理说明 xml布局文件解析成View树的流程分析. 希望对大家能有帮助.- - 分析版本基于Android 2.3 . 1.WRAP_CONTENT.MATCH_PARENT/FILL_PARENT 初入Android殿堂的同学们,对这三个属性一定又爱又恨.爱的是使

Android——ListView多布局+适配器(二)

Android--ListView多布局+适配器(二) <span style="font-size:18px;">package com.example.administrator.newstop.entity; /** * Created by Administrator on 2016/8/4. */ public class News { private String title; private String pubDate; private int img; p

android :点击某个按钮弹出在原有布局中没有(或者存在)内容 :以删除原有布局内容为例

主要涉及了(1)对布局中某个控件的监听 (2)在布局文件中设置可显示,删除的参数 visibility的参数的有三个,在这里我只设置了一个,可见的. android:visibility="visible" 剩下的和他的用法相同. (3)在代码中监听控件后,对visibility的参数重新设置. 效果图:点击按钮后edittext不见了 (1)点击高级按钮前 (2)点击高级按钮后 (1)布局文件 <?xml version="1.0" encoding=&qu

Android中将xml布局文件转化为View树的过程分析(下)-- LayoutInflater源码分析

在Android开发中为了inflate一个布局文件,大体有2种方式,如下所示: // 1. get a instance of LayoutInflater, then do whatever you want LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // 2. you're in some View class, then jus

Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上

                                                                                                                                               本文原创, 转载请注明出处:http://blog.csdn.net/qinjuning 在之前一篇博文中<<Android中View绘制流程以及invalidate()等相关方法分析>>,简单的阐述