Android入门:Layout
来源:互联网 发布:佳能软件dpp 4.0 编辑:程序博客网 时间:2024/05/01 05:25
AbsoluteLayout因为已被废除,因此不做介绍;
只要存在界面,就会有布局的存在,就像Swing,虽然一个是桌面应用,一个是手机应用,但是他们都差不多。
只要存在界面,就会有布局的存在,就像Swing,虽然一个是桌面应用,一个是手机应用,但是他们都差不多。
1.LinearLayout
默认布局。组件的排列按照预先定义方向很有序的排列,类似于Swing中的FlowLayout;
注意点:
(1)可以在<LinearLayout>中添加android:orientation:vertical/horizontal ;
(2)可以嵌套<LinearLayout>;
每个组件都在左上角,如果多个组件一起出现,则会重叠,类似于git叠加的动画;
2.FrameLayout
每个组件都在左上角,如果多个组件一起出现,则会重叠,类似于git叠加的动画;
应用:在线视频播放器
当点击按钮,则开始播放视频;
main.xml
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/frame3" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/frame2" android:layout_gravity="center"//居中 /></FrameLayout>
3.RelativeLayout
每个组件定位都是按照与其他组件的上下、左右定位;
默认的定位为左上方;
(1)定位与组件的上下左右
(1)定位与组件的上下左右
android:layout_below="@id/.."
android:layout_above="@id/"
android:layout_toLeftOf="@id/"
android:layout_toRightOf="@id/"
(2)定位与组件的边缘对齐
android:layout_alignLeft="@id/"
android:layout_alignRight="@id/"
android:layout_alignTop="@id/"
android:layout_alignBottom="@id/"
(3)定位与父组件的边缘对齐
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
(4)与整个屏幕的关系
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
(5)组件间的距离
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_margin="5dp"
4.TableLayout
类似于Swing中的GridLayout;
表格布局的每行用<TabRow>括起来;
在<TableLayout>中可以定义如下属性:
(1)android:shrinkColumns="1" 表明第2个控件如果里面的内容过多,会收缩,扩展到第二行,而不是延伸;
(2)android:stretchColumns="2" 如果有空白,第3个控件填充;
在控件中设置:
(1)android:layout_column="2" 将此控件放在第3个位置;
(2)android:layout_span="2" 此控件占据2个单元位置;
Tips:简单布局工具droiddraw
http://code.google.com/p/droiddraw/downloads/detail?name=droiddraw-r1b22.zip&can=2&q=
- android layout 入门总结
- Android入门:Layout
- layout入门
- layout-入门
- Android入门笔记之标签布局(Tab Layout)
- Android入门-短信-layout中getX,getLeft等的区别
- Android开发入门记录1——layout
- android layout
- android layout
- Android Layout
- Android Layout
- Android Layout
- android layout
- android layout
- Android Layout
- Android Layout
- android : Layout
- android layout
- Java异常处理的陋习
- RTP/AVP
- 让人吃惊的专家们和编辑们啊
- activity跳转之后item标志逻辑错误
- PHP图片验证码的实现
- Android入门:Layout
- 遍历指定目录下的图片文件 显示在gridview
- CentOS 安装多种解码器打造Linux的全能播放器
- 清明節をしのぶ作者トマト文
- Eclipse设置:背景与字体大小和xml文件中字体大小调整
- Linux(FC)下播放rm rmvb mp3 wma 等各种媒体文件的解决方法
- mysql数据文件的导入导出
- [ASP.net教程] 新浪OAuth网站登陆连接,请求access_token时遇到21323 miss client id or secret 的解决方案
- 大二暑期学习计划