首页 后端开发 XML/RSS教程 XML布局文件的代码案例分享

XML布局文件的代码案例分享

Mar 21, 2017 pm 04:26 PM

XML布局文件

在文件夹res/layout中存放着xml格式的布局文件

布局方式主要是LinearLayout(线性布局) 、TableLayout(表格布局)、RelativeLayout(相对布局) 

当然还有AbsoluteLayout、(绝对布局)、FrameLayout(帧布局)等等

他们之间也可以通过嵌套达到更好的界面效果

我按照个人的理解将常用的属性整理了一下

可能不科学 但我认为很实用。

控件为整体:

    android:id                                                地址

    android:width                                           宽度

    android:height                                         高度

    android:layout_width                               宽(fill_parent/wrap_content)

    android:layout_height                             高(fill_parent/wrap_content)

    android:layout_margin(Left/Top/Right/Bottom)    外边距(*dip)

    android:layout_weight                             比重

控件内容:

    android:text                                         文本内容

    android:textSize                                   文本大小

    android:gravity                                     内容基本位置

    android:background                               背景色(RBG)

    android:padding(Left/Top/Right/Bottom)    内边距(*dip)

    android:singleLine                                  内容同行显示(true/false)

相对布局:

  android:layout_above                                下边与谁的上边对齐(id)

    android:layout_below                                 上边与谁的下边对齐(id)

    android:layout_toLeftOf                             右边与谁的左边对齐(id)

    android:layout_toRightOf                           左边与谁的右边对齐(id)

   android:layout_alignTop                            上边与谁的上边对齐(id)

    android:layout_alignBottom                       下边与谁的下边对齐(id)

    android:layout_alignLeft                            左边与谁的左边对齐(id) 

    android:layout_alignRight                          右边与谁的右边对齐(id)

 

    android:layout_alignParentTop                  上边与父控件的上边对齐(true/false)

    android:layout_alignParentBottom             下边与父控件的下边对齐(true/false)

    android:layout_alignParentLeft                  左边与父控件的左边对齐(true/false)

    android:layout_alignParentRight                右边与父控件的右边对齐(true/false)

    android:layout_centerInParent                   相对父控件居中(true/false)        

    android:layout_centerHorizontal                 相对父控件水平方向居中(true/false)

    android:layout_centerVertical                     相对父控件垂直方向居中(true/false)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

下面给出我刚做好的注册页面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    >
    
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
 
<TextView 
    android:text="欢迎注册" 
    android:gravity="center"
    android:textSize="15pt"
    android:textColor="#ff8c00"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></TextView>
 
<TextView 
    android:text=" 性别/Gender" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/genderGroup" android:orientation="horizontal">
<RadioButton android:id="@+id/maleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男"></RadioButton>
<RadioButton android:id="@+id/femaleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女"></RadioButton>

</RadioGroup>
 
<TextView 
    android:text=" 用户名/User" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<EditText 
    android:id="@+id/user" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></EditText>
 
<TextView 
    android:text=" 密码/Password" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<EditText 
    android:id="@+id/password" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></EditText>
 
<TextView 
    android:text=" 重复密码/Re-type Password" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<EditText 
    android:id="@+id/rpassword" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></EditText>
 
<CheckBox 
    android:text="同意注册条款*" 
    android:id="@+id/CheckBox01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    ></CheckBox>
 
</LinearLayout>
 
<TableRow 
    android:layout_alignParentBottom="true"
    android:id="@+id/TableRow01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
<Button 
    android:id="@+id/confirm" 
    android:text="confirm" 
    android:textSize="10pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    ></Button>
<Button 
    android:textSize="10pt" 
    android:text="cancel" 
    android:layout_width="wrap_content" 
    android:id="@+id/cancel" 
    android:layout_height="wrap_content"
    android:layout_weight="1"
    ></Button>
</TableRow>
</RelativeLayout>
登录后复制

1255.jpg

以上是XML布局文件的代码案例分享的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
威尔R.E.P.O.有交叉游戏吗?
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

能否用PowerPoint打开XML文件 能否用PowerPoint打开XML文件 Feb 19, 2024 pm 09:06 PM

XML文件可以用PPT打开吗?XML,即可扩展标记语言(ExtensibleMarkupLanguage),是一种被广泛应用于数据交换和数据存储的通用标记语言。与HTML相比,XML更加灵活,能够定义自己的标签和数据结构,使得数据的存储和交换更加方便和统一。而PPT,即PowerPoint,是微软公司开发的一种用于创建演示文稿的软件。它提供了图文并茂的方

使用Python实现XML数据的合并和去重 使用Python实现XML数据的合并和去重 Aug 07, 2023 am 11:33 AM

使用Python实现XML数据的合并和去重XML(eXtensibleMarkupLanguage)是一种用于存储和传输数据的标记语言。在处理XML数据时,有时候我们需要将多个XML文件合并成一个,或者去除重复的数据。本文将介绍如何使用Python实现XML数据的合并和去重的方法,并给出相应的代码示例。一、XML数据合并当我们有多个XML文件,需要将其合

使用Python实现XML数据的筛选和排序 使用Python实现XML数据的筛选和排序 Aug 07, 2023 pm 04:17 PM

使用Python实现XML数据的筛选和排序引言:XML是一种常用的数据交换格式,它以标签和属性的形式存储数据。在处理XML数据时,我们经常需要对数据进行筛选和排序。Python提供了许多有用的工具和库来处理XML数据,本文将介绍如何使用Python实现XML数据的筛选和排序。读取XML文件在开始之前,我们需要先读取XML文件。Python有许多XML处理库,

Python中的XML数据转换为CSV格式 Python中的XML数据转换为CSV格式 Aug 11, 2023 pm 07:41 PM

Python中的XML数据转换为CSV格式XML(ExtensibleMarkupLanguage)是一种可扩展标记语言,常用于数据的存储和传输。而CSV(CommaSeparatedValues)则是一种以逗号分隔的文本文件格式,常用于数据的导入和导出。在处理数据时,有时需要将XML数据转换为CSV格式以便于分析和处理。Python作为一种功能强大

使用PHP将XML数据导入数据库 使用PHP将XML数据导入数据库 Aug 07, 2023 am 09:58 AM

使用PHP将XML数据导入数据库引言:在开发中,我们经常需要将外部数据导入到数据库中进行进一步的处理和分析。而XML作为一种常用的数据交换格式,也经常被用来存储和传输结构化数据。本文将介绍如何使用PHP将XML数据导入数据库。步骤一:解析XML文件首先,我们需要解析XML文件,提取出需要的数据。PHP提供了几种解析XML的方式,其中最常用的是使用Simple

Python实现XML和JSON之间的转换 Python实现XML和JSON之间的转换 Aug 07, 2023 pm 07:10 PM

Python实现XML和JSON之间的转换导语:在日常的开发过程中,我们常常需要将数据在不同的格式之间进行转换。XML和JSON是常见的数据交换格式,在Python中,我们可以使用各种库来实现XML和JSON之间的相互转换。本文将介绍几种常用的方法,并附带代码示例。一、XML转JSON在Python中,我们可以使用xml.etree.ElementTree模

使用Python处理XML中的错误和异常 使用Python处理XML中的错误和异常 Aug 08, 2023 pm 12:25 PM

使用Python处理XML中的错误和异常XML是一种常用的数据格式,用于存储和表示结构化的数据。当我们使用Python处理XML时,有时可能会遇到一些错误和异常。在本篇文章中,我将介绍如何使用Python来处理XML中的错误和异常,并提供一些示例代码供参考。使用try-except语句捕获XML解析错误当我们使用Python解析XML时,有时候可能会遇到一些

Python解析XML中的特殊字符和转义序列 Python解析XML中的特殊字符和转义序列 Aug 08, 2023 pm 12:46 PM

Python解析XML中的特殊字符和转义序列XML(eXtensibleMarkupLanguage)是一种常用的数据交换格式,用于在不同系统之间传输和存储数据。在处理XML文件时,经常会遇到包含特殊字符和转义序列的情况,这可能会导致解析错误或者误解数据。因此,在使用Python解析XML文件时,我们需要了解如何处理这些特殊字符和转义序列。一、特殊字符和

See all articles