Android 布局管理器(Layout)

本文详细介绍了Android中常见的布局管理器,包括LinearLayout、TableLayout、RelativeLayout、AbsoluteLayout和FrameLayout的使用方法和特点。通过XML布局文件展示了各布局的示例,帮助开发者理解如何创建和配置这些布局。
摘要由CSDN通过智能技术生成

线性布局:LinerLayout

表格布局:TableLayout

相对布局:RelativeLayout

绝对布局:AbsoluteLayout

帧布局:FrameLayout

 

定义并展现视图层次的最常用的方法是使用XML布局文件。XML中的每个元素都是View或ViewGroup对象(或他们的子类)。

 

1.线性布局

注:纵向vertical或横向horizontal

eg:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout//<TextView>没有在该命名空间中,因此其前面无需加上“android:”做前缀

xmlns:android="http://schemas.android.com/apk/res/android"      //其属性“xmlns:android”指定命名空间,顶级元素必须指定命名空间。

android:orientation="vertical"//属性“orientation”指定子元素排列方式,其中指定为“vertical”则是子元素垂直排列,而另一个为“horizontal”代表子元素水平排列,

android:layout_width="fill_parent"//“fill_parent”=“match_parent代表填满其父元素,“wrap_content”代表该元素的大小仅包裹其自身内容

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"//layout_width该元素的宽度

android:layout_height="wrap_content"//layout_height该元素的高度

android:text="@string/name_text"

/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/cancle_button"

/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/ok_button"/>

</LinearLayout>

2.表格布局:

TableLayout属于行和列形式的管理控件,每行为一个TableRow对象,也可以是一个View对象。

在TableRow中还可以继续添加其他的控件,每添加一个子控件就成为一列。TableLayout不会生成边框。

Android:collapseColumns  设置指定的列为collapse,如果一列被标示为collapse,该列会被隐藏

Android:shrinkColumns      设置指定的列为shrinkable,如果一列被标示为shrinkableÿ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值