Android - 应用程序的layout

     android应用程序在显示Activity时,需对其显示的的布局进行定义,定义文件在res/layout文件夹下,采用xml文件存储,与Activity同名。

一个简单的布局文件内容:

 -------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/all_white"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:textColor="@color/all_black"
    android:gravity="center_horizontal"
    />
</LinearLayout>

 --------------------------------------------------------------------------------------------------------

1 布局类型:LinearLayout

常用定义属性

布局方向(垂直布局):      android:orientation="vertical" 
布局宽度(填满父窗口):   android:layout_width="fill_parent"
布局高度(填满父窗口):   android:layout_height="fill_parent"

对应于控件

控件ID:android:id

控件文本:android:text

控制文本位置:android:gravity

文本大小:android:textSize

背景色:android:background

左边距:android:paddingLeft

上边距:android:paddingTop

右边距:android:paddingRight

下边距:android:paddingBottom

在整体布局中大小比例:android:layout_weight

单行显示:android:singleLine


2 布局类型:TableLayout

定义行<TableRow>

扩展列空间:android:stretchColumns


3 布局类型:RelativeLayout

---------------------------------------------------------------------------------------------------------------------

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10px"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
android:id="@+id/label"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Type here"
    />
<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/ok"
    android:layout_alignTop="@id/ok"
    android:text="Cancel"
    />
</RelativeLayout>

-------------------------------------------------------------------------------------------------------------

给定控件上:android:layout_above

给定控件下:android:layout_below

给定控件左:android:layout_toLeftOf

给定控件右:android:layout_toRighOf


基线对齐:android:layout_alignBaseline

下边缘对齐:android:layout_alignBottom

左边缘对齐:android:layout_alignLeft

右边缘对齐:android:layout_alignRight

上边缘对齐:android:layout_alignTop


与父控件下边对齐:android:layout_alignParentBottom

与父控件左边对齐:android:layout_alignParentLeft

与父控件右边对齐:android:layout_alignParentRight

与父控件上边对齐:android:layout_alignParentTop


水平居中:android:layout_centerHorizontal

平面中心:android:layout_centerInParent

垂直居中:android:layout_centerVerical


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值