您的位置:首页 > 移动开发 > Android开发

Android学习笔记-- Activity的布局

2011-02-13 08:10 225 查看
MicrosoftInternetExplorer402DocumentNotSpecified7.8Normal0
LinearLayout 线性布局 TableLayout 表格布局

//下面分别演示以上两种布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Android:orientation="horizeontal"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent">
<TextView android:id="@+id/firstView"
Android:text -- 指定文本内容
Android:grivity -- 基本位置 eng
Android:textSIze -- 文字大小 pt
Android:background -- 背景颜色 #fff
Android:width
Android:height
Android:padding --控件内边距 dip
Android:sigleLine -- 控件的内容是否在同一行显示 boolean
Android:weight -- 控件占linearlayout的比例
Android:layout_width
Android:layout_height
</LinearLayout>

2 . <TableLayout android:stretchColumns="1"> // 指定列拉伸
<TableRow>
// 填写控件
</TableRow>
<TableRow>
// 两行
</TableRow>
</TableLayout>

3 . LinearLayout高级布局



例 : 思想3个LinearLayout
<LinearLayout xmlns:android="http://schmas.android.com/apk/res/android"
Android:orientation="vertical" -- 垂直布局
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
>

<LinearLayout
Android:orientation="horizontal" -- 水平布局
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:layout_weight="1" -- 比例相等
>

</LinearLayout>

<LinearLayout
Android:orientation="vertical" -- 垂直布局
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:layout_weight="1">
</LinearLayout>

</LinearLayout>

注 : 在LinearLayout中还可以嵌套TableLayout

4 . RelativeLayout相对布局

Relative常见属性的概要
Android:layout_above -- 将该控件的底部至于给定ID的控件之上
Android:layout_Below -- 将该控件的底部至于给定ID的控件之下
Android:layout_toLeftOf -- 该控件的右边缘个给定ID的控件的左边缘对齐
Android:layout_toRightOf -- 该控件的左边缘个给定ID的控件的右边缘对齐

Layout_alignBaseline -- 该控件的baseline与给定ID的控件的baseline对齐
Layout_alignBottom -- 该控件的底部边缘与给定ID的控件的底部边缘对齐
Layout_alignLeft -- 该控件的左边缘个给定ID的控件的左边缘对齐
Layout_alignRight -- 该控件的右边缘个给定ID的控件的右边缘对齐
Layout_alignTop -- 该控件的顶部边缘与给定ID的控件的顶部边缘对齐

Layout_alignParentBottom , Layout_alignParentLeft , Layout_alignParentRight , Layout_alignParentTop 该值为True时 , 该控件的边与父控件的边的对齐方式

Layout_centerHorizontal , Layout_centerInParent , Layout_centerVertical



<RelativeLayout xmlns:anroid="http://schmas.android.com/apk/res/android"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:padding="10px" >

<TextView Android:id="@+id/label"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:text="Type Here:" />

<EditText Android:id="@+id/entry"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:background="@android:dravable/editbox_background" -- 默认编辑框的颜色
Android:layout_below="@id/label" />

<Button Android:id="@+id/ok"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_below="@id/entry"
Android:layout_alignParentRight="true"
Android:layout_marginLeft="10px"
Android:text="OK" />

<Button Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_toLeftOf="@id/ok"
Android:layout_alignTop="@id/ok"
Android:text="Cancal" />

</RelativeLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: