(转载)Android界面布局浅议
来源:互联网 发布:合肥优化外包公司 编辑:程序博客网 时间:2024/05/20 07:37
一、线性布局LinearLayout与表格布局TableLayout的使用
二、相对布局实现较复杂的布局
1、LinearLayout的使用:
<?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"
>
<TextView
android:id="@+id/textView1"
android:text="这是第一行"
android:textColor="#0112aa"
android:textSize="20pt"
android:background="#00aa00"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="23dip"
android:layout_weight="1"
android:singleLine="true"
/>
<TextView
android:id="@+id/textView2"
android:text="这是第二行"
android:textSize="12pt"
android:background="#0000aa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
2、TableLayout的使用:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
>
<TableRow>
<TextView
android:text="@string/r1c1"
android:background="#00aa00"
android:padding="10dip" />
<TextView
android:text="@string/r1c1"
android:background="#fd0011"
android:gravity="right"
android:padding="10dip"/>
<TextView
android:text="@string/r1c2"
android:background="#0000aa"
android:padding="10dip" />
</TableRow>
<TableRow>
<TextView
android:text="@string/r2c1"
android:background="#fd0011"
android:padding="10dip" />
<TextView
android:text="@string/r2c2"
android:background="#00aa00"
android:gravity="center_horizontal"
android:padding="10dip" />
</TableRow>
</TableLayout>
3、RalativeLayout的使用
<?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="wrap_content"
>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="type here" />
<EditText
android:id="@+id/editView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView"
android:text="在这里填写内容:" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_below="@id/editView"
android:layout_alignParentRight="true"
android:layout_marginLeft="12px" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/button"
android:layout_below="@id/editView"
android:text="Ok" />
</RelativeLayout>
RalativeLayout中各属性值的含义
分四类
第一类:
android:layout_above: 将该控件置于指定控件之上
android:layout_below: 将该控件置于指定控件之下
android:layout_toLeftOf: 将该控件置于指定控件的左方
android:layout_toRightOf: 将该控件置于指定控件的右方
第二类(当前控件与其他控件):
android:layout_alignTop: 使该控件的上边缘和指定控件的上边缘对齐
android:layout_alignBottom: 使该控件的下边缘和指定控件的下边缘对齐
android:layout_alignLeft: 使该控件的左边缘和指定控件的左边缘对齐
android:layout_alignRight: 使该控件的右边缘和指定控件的右边缘对齐
android:layout_alignBaseline: 使该控件的baseline和指定控件的baseline对齐
第三类(当前控件与父控件):
android:layout_alignParentTop: 如果值为true,使该控件靠向父控件的上边缘
android:layout_alignParentBottom: 如果值为true,使该控件靠向父控件的下边缘
android:layout_alignParentLeft: 如果值为true,使该控件靠向父控件的左边缘
android:layout_alignParentRight: 如果值为true,使该控件靠向父控件的右边缘
第四类:
android:layout_centerHorizontal: 如果值为true,将该控件置于水平方向的中央
android:layout_centerVertical: 如果值为true,将该控件置于垂直方向的中央
android:layout_centerInParent: 如果值为true,将该控件置于水平方向和垂直方向的中央
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lganggang131/archive/2011/03/15/6251441.aspx
- (转载)Android界面布局浅议
- java界面中的布局管理器(转载)
- android界面布局----TableLayout(表单布局)
- android 界面布局(大概)
- 【转载】Android软件开发之盘点界面五大布局(十六)
- Android UI布局 —— 仿QQ登录界面(转载)
- Android 学习笔记 (3)界面布局
- Android界面基本属性 (布局)
- Android学习0818<二>(界面布局)
- android布局实践(一)home界面
- android布局实践(二)login界面
- Android界面布局实例
- Android的界面布局
- Android界面布局详解
- android 界面布局
- android动态界面布局
- android 界面布局
- android 界面布局
- 图像解码之三——giflib解码gif图片
- __attribute__ 机制
- sqlserver获取第n行数据
- 数据源绑定JNDI步骤以及绑定后数据源存放路径
- 第11章 Windows应用程序高级控件
- (转载)Android界面布局浅议
- mpc-hc的编译说明
- JDBC连接多个SQLServer实例
- Project facet Java version 6.0 is not supported.解决办法
- 我个技术宅也无聊了自编一个植物大战僵尸网上在线恶搞版(有视频有游戏有真相)
- 一个模块接口的组成
- Windows SDK入门浅谈 — 写给初学者
- About "Rsync"
- .NET调用Apache Axis实现的Web Service