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核实处理。

  • 相关标签:XML,布局文件
  • 程序员必备接口测试调试工具:点击使用

    Apipost = Postman + Swagger + Mock + Jmeter

    Api设计、调试、文档、自动化测试工具

    网页生成APP,用做网站的技术去做APP:立即创建

    手机网站开发APP、自助封装APP、200+原生模块、2000+映射JS接口按需打包

    • 上一篇:Xml序列化的图文代码详解
    • 下一篇:详细介绍XSLT模板转换XML文档的代码案例分析

    相关文章

    相关视频


    • 使用xmlhttp为网站增加域名查询功能的示例代码...
    • 四种XML解析方式详解
    • 基于PHP对XML的操作详解
    • XML和Tomcat的入门知识的详细介绍
    • XML布局文件的代码案例分享
    • Vue3 事件修饰符
    • vue3 指令
    • vue3 基础语法
    • vue3 组合api和选项api介绍

    视频教程分类

    • php视频教程
    • html视频教程
    • css视频教程
    • JS视频教程
    • jQuery视频教程
    • mysql视频教程
    • Linux视频教程
    • Python视频教程
    • Laravel视频教程
    • Vue视频教程

    专题

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