android布局
Android组件---四大布局的属性详解

Android组件---四⼤布局的属性详解【声明】欢迎转载,但请保留⽂章原始出处→_→Android常见布局有下⾯⼏种:LinearLayout:线性布局。
所有的控件都是串在⼀条线上的。
RelativeLayout:相对布局。
所有的控件的位置,都是相对于⽗控件的。
FrameLayout:帧布局。
FrameLayout布局中的控件都是⼀层⼀层的。
帧布局每次添加的控件都显⽰在最上⾯,最后显⽰在界⾯上的是最后添加的⼀个控件。
TableLayout:表格布局。
表格布局可以实现的.⼀般可以使⽤线性布局实现。
AbsoluteLayout:绝对布局。
已经是废弃的状态,很少⽤了。
orientation:属性是指定线性布局的排列⽅向。
horizontal ⽔平。
线性布局默认的朝向是⽔平的。
vertical 垂直例如:android:orientation="vertical"gravity:指定当前控件⾥⾯的内容容显⽰位置。
(四⼤layout中均可使⽤)left 左边right 右边top 上边bottom 底边例如:android:gravity="center"gravity中的属性可以组合使⽤。
例如:android:gravity="bottom|right"layout_gravity:指定当前控件在⽗元素的位置。
(只在 LinearLayout 和 FrameLayout 中有效)left 左边right 右边top 上边bottom 底边centercenter_horizontalcenter_vertical例如:android:layout_gravity="center"另外,需要提⽰的是,对于 LinearLayout :当 android:orientation="vertical" 时,只有⽔平⽅向的设置才起作⽤,垂直⽅向的设置不起作⽤。
Android布局属性大全

Android布局属性大全布局:AbsoluteLayout(绝对布局):xmlns:android="/apk/res/android"style="@..."android:clipChildren="true|false"android:clipToPadding="true|false"android:layoutAnimation="@---"android:animationCache="true|false"android:persistentDrawingCache="none|animation|scrolling|all":持续高速缓存绘图android:alwaysDrawnWithCache="true|false"android:andStatesFromChildre="true|false"android:descendantFocusability="beforeDescendants|afterDescendants|bl ocksDescendants":后裔可聚焦android:id="@+id/absoluteLayout"android:tag="@---"android:android:scrollX="---"android:android:scrollY="---"android:background="@---"android:padding="----"android:paddingLeft="----"android:paddingTop="----"android:paddingRight="----"android:paddingBotton="---"android:focusable="true|false"android:focusableInTouchMode="true|false"android:visibility="visible|invisible|gone"android:fitsSystemWindows="true|false":适合系统窗口android:scrollbars="none|horizontal|vertical"android:scrollbarStyle="insideOverlay(内覆盖)|insideInset(内插图)|outsideOverlay(外覆盖)|outsideInset(外插图)"android:isScrollContainer="true|false":是一个滚动集合android:fadeScrollbars="true|false":褪色的滚动条android:scrollbarFadeDuration="---":卷轴淡出android:scrollDefaultDelayBeforeFade="---":滚动前默认延迟android:scrollbarSize="---"android:scrollbarThumbHorizontal="@----":拇指水平滚动条android:scrollbarThumbVertical="@----":拇指垂直滚动条android:scrollbarTrackVertical="@---":垂直滚动条轨道android:scrollbarTrackHorizontal="@---":水平滚动条轨道android:scrollbarAlwaysDrawHorizontalTrack="true|false":水平滚动条总是吸引轨道android:scrollbarAlwaysDrawVerticalTrack="true|false":垂直滚动条总是吸引轨道android:fadingEdge="none|horizontal|vertical":衰落的边缘android:fadingEdgeLength="---":边长衰落android:nextFocusLeft="----":下左焦点android:nextFocusUp="---":下一个重点注册android:nextFocusRight="---":正确的下一个重点android:nextFocusDown="---":下一个焦点下移android:clickable="true|false":点击android:longClickable="true|false"android:saveEnabled="true|false":启用保存android:drawingCacheQuality="auto|low|hight":绘图缓存质量android:keepScreenOn="true|false":保持屏幕android:duplicateParentState="true|false":重复父状态android:minHeight="---":android:minWidth="----":android:soundEffectEnabled="true|false":音效启用android:hapticFeedbackEnable="true|false":触觉反馈启用android:contentDescription="@---":内容概述android:onClick="@---":android:layout_gravity="top|bottom|right|left|center_vertical|center_ horizontal|fill_vertical|fill_horizontal|center|fill|clip_vertical|cl ip_horizontal":重力android:layout_width="fill_parent|match_parent|wrap_content" android:Llayout_height="fill_parent|match)parent_wrap_content" android:layout_margin="":android:layout_marginLeft=""android:layout_marginTop=""android:layout_marginRight=""android:layout_marginBottom=""DialerFilter(拨号器过滤器):ExpandableListView(可扩展的列表视图):FrameLayout(针布局):GridView(网格视图):HorizontalScrollView(水平滚动查看):ImageSwither(图像切换):LinearLayout(线性布局):ListView(列表视图):MediaController(媒体控制器):RadioGroup(单选按钮组):RelativeLayout(相对布局):ScrollView(滚动查看):SlidingDrawer(滑动抽屉):TabHost(标签主机):TabWidget(标签控件):TableLayout(表格布局):TableRow(表行):TextSwitcher(文字切换):ViewAnimator(查看动画):ViewFlipper(参看弗利珀):ViewSwitcher(查看切换):--------------------------------------------------- GestureOverlayView(手势覆盖查看):SurfaceView(表现观):View(参看):ViewStub(查看存根):WebView(WEB视图):AnalogClock(模拟时钟):AutoCompleteTextView(自动完成文本视图):Button(按钮):CheckBox(复选框):CheckedTextView(检查的文字查看):Chronometer(时计):DatePicker(日期选择器):DigitalClock(数字时钟):EditText(编辑文字):Gallery(画廊):ImageButton(图像按钮):ImageView(图像查看):MultiAutoCompleteTextView(多自动完成文本查看): ProgressBar(进度):QuickContactBadge(快速联系徽章):Radio Button(单选按钮):RatingBar(评分酒吧):SeekBar(搜索栏:即拖拉进度条):Spinner(微调):TextView(文本视图):TimePicker(时间选择器):ToggleButton(切换按钮):TwoLineListItem(两线列表项):VideoView(视频查看):ZoomButton(变焦按钮):ZoomControls(缩放控制):Include(包括):-------------------------------<merge></merge>(合并):xmlns:android="/apk/res/android"android:layout_gravity="top|bottom|left|right|center_vertical|fill_ve rtical|center_horizontal|fill_horizontal|center|fill|clip_vertical|cl ip_horizontal"android:layout_width="fill_parent|match_parent|wrap_content" android:layout_height="fill_parent|match_parent|wrap_content" android:layout_margin=""android:layout_marginLef=""android:layout_marginTop=""android:layout_marginRight=""android:layout_marginBottom=""第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中android:layout_centerVertical 垂直居中android:layout_centerInparent 相对于父元素完全居中android:layout_alignParentBottom 贴紧父元素的下边缘android:layout_alignParentLeft 贴紧父元素的左边缘android:layout_alignParentRight 贴紧父元素的右边缘android:layout_alignParentTop 贴紧父元素的上边缘android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物第二类:属性值必须为id的引用名“@id/id-name”android:layout_below 在某元素的下方android:layout_above 在某元素的的上方android:layout_toLeftOf 在某元素的左边android:layout_toRightOf 在某元素的右边android:layout_alignTop 本元素的上边缘和某元素的的上边缘对齐android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐第三类:属性值为具体的像素值,如30dip,40pxandroid:layout_marginBottom 离某元素底边缘的距离android:layout_marginLeft 离某元素左边缘的距离android:layout_marginRight 离某元素右边缘的距离android:layout_marginTop 离某元素上边缘的距离EditText的android:hint 设置EditText为空时输入框内的提示信息。
安卓之布局总结

安卓之布局总结Adroid布局有⼈形象地⽐喻,Android开发中的布局就相当于⼀栋建筑的外观架构。
布局⽤得好,这栋建筑的外观才美观⾼⼤上。
Android布局管理器Android布局管理器本⾝是⼀个界⾯控件,所有的布局管理器都是ViewGroup类的⼦类,都是可以当做容器类来使⽤的。
因此⼀个布局管理器中可以嵌套其他的布局管理器。
这是⾕歌上找的⼀张布局管理器层级图每⼀个ViewGroup都可以嵌套其他的ViewGroup和View(视图)。
⼀个ViewGroup的⼤⼩是相对的,它即可以是其他ViewGroup的⽗容器,也可以是其他ViewGroup的⼦容器。
在Android中,ViewGroup指代的是布局管理器,也就是下⾯要讲的布局样式,View指代的是布局管理器中的⼀个个控件。
在Android中,控件可以在XML⽂件中定义,也可以程序员根据⾃⼰的需要去定义⼀个类。
本⽂重点先不讨论视图中的控件,还是回归到布局。
Android六⼤基本布局管理器分别是:线性布局(LinearLayout)、表格布局(TableLayout)、⽹格布局(GridLayout)、相对布局(RelativeLayout)、绝对布局(AbsoluteLayout)、层布局(FrameLayout)其中,表格布局是线性布局的⼦类。
⽹格布局是android 4.0后新增的布局。
(1)线性布局线性布局会将容器内的所有控件⼀个挨着⼀个地排列。
属性:1. 排列⽅向android:orienation = “ horizontal/vertical”⽔平排列和垂直排列,Android中默认为垂直排列vertical注意:默认情况下⽔平和垂直⽅向的排列只占⼀⾏,如果⽤android:layout_width来设定控件的宽度,如果控件宽度太⼤,超出屏幕的显⽰范围,屏幕是不会显⽰超出的范围的。
2. 对齐⽅式⽤于控制元素(例如⽂字)在该控件⾥的显⽰位置。
android线性布局

android线性布局示例LinearLayout是android中常见的布局形式。
可垂直或者水平平分或者根据权重分配空间,罗列视图小窗口组件。
也就是说,如果垂直线性布局的话,一行只能布局一个窗口部件,水平则相应的只有一行,在该行内显示各个窗口部件,不会折行。
使用线性布局,可以实现类似下面图示的界面。
参见:/guide/topics/ui/layout-objects.html对示例和布局有详细的描述。
这里根据上面图,写了一个例子。
主要展示了以下技术要点:∙Activity的跳转,可通过实现android activity之间的跳转帮助理解,这里示例利用到Activity跳转,导航到具体示例Activity上;∙线性布局的属性,android:layout_height和android:layout_width,可以产生不同的效果。
这是第一种线性布局效果:可以看到文本框是单行的,评论的文本框没有占据屏幕剩余部分。
代码见:/svn/tags/yout.demo_1.0/第二个示例,效果:评论文本框占据余下的屏幕部分。
主要是linear.demo.xml文件中的layout_width属性做了修改,其他文件没有变化。
代码见:/svn/tags/yout.demo_1.1官方网站上有一个对权重的示例。
见:/resources/tutorials/views/hello-linearla yout.html效果类似这样:可以通过修改布局文件中的android:layout_weight属性,让色条改变分配比例。
权重值越高,所占比例越大。
见布局文件片段:<LinearLayout android:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"><TextView android:text="red" android:gravity="center_horizontal" android:background="#aa0000" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="3" /><TextView android:text="green" android:gravity="center_horizontal" android:background="#00aa00" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" /><TextView android:text="blue" android:gravity="center_horizontal" android:background="#0000aa" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="2" /><TextView android:text="yellow" android:gravity="center_horizontal" android:background="#aaaa00" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" />。
Android之界面布局

用户界面基础
用户界面(User Interface,UI)是系统和用户之间 进行信息交换的媒介,实现信息的内部形式与人类 可以接受形式之间的转换
在计算机出现早期,批处理界面(1946-1968)和命令行 界面(1969-1983)得到广泛的使用 目前,流行图像用户界面(Graphical User Interface, GUI),采用图形方式与用户进行交互的界面 未来的用户界面将更多的运用虚拟现实技术,使用户能 够摆脱键盘与鼠标的交互方式,而通过动作、语言,甚 至是脑电波来控制计算机
// 定义布局管理器的指定宽和高 youtParams params = new youtParams( youtParams.FILL_PARENT, youtParams.FILL_PARENT); layout.setOrientation(LinearLayout.VERTICAL);
<Button android:id="@+id/btn1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="gravity测试" android:gravity="right" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="layout_gravity测试" android:layout_gravity="right" />
Android常见界面布局线性布局LinearLayout优秀文档

第2章 Android常见界面布局 —第—2章移动An软dr件oid开常发见(界A面nd布ro局id) 第—2—章移动An软dr件oid开常发见(界A面nd布ro局id) 4第—2—线章移性动A布n软局dr件Loind开e常发a见rL(a界Ayo面nud布tro局id)
布局可以分为水平线性布局和 —第—2章移动An软dr件oid开常发见(界A面nd布ro局id)
线第4 性2线章布性局A布n(局drLLoiinndee常aar见rLLaa界yyoo面uut布t)局是以水平或者垂直的方式来显示界面中添加的控件,因此线性布局可以分为水平线性布局和垂直线性布局两 种第—。2—章移动An软dr件oid开常发见(界A面nd布ro局id) 4 线性布局LinearLayout 4第2线章性A布n局drLoinde常a见rLa界yo面u布t 局
第2章 Android常见界面布局
——移动软件开发(Android)
2.4 线性布局LinearLayout
线性布局(LinearLayout)是
4 线性布局LinearLayout
以水平或者垂直的方式来显示 —4 —线移性动布软局件Lin开e发arL(aAyonudtroid)
4第2线章性A布n局drLoinde常a见rLa界yo面u布t 局 第—2—章移动An软dr件oid开常发见(界A面nd布ro局id) 第4 2线章性A布n局drLoinde常a见rLa界yo面u布t 局
垂直线性布局两种。下面我们 第2章 Android常见界面布局
第线2性章布局An(drLoiinde常ar见La界yo面ut布)局是以水平或者垂直的方式来显示界面中添加的控件,因此线性布局可以分为水平线性布局和垂直线性布局两 种。
Android开发自学笔记(AndroidStudio)—4.1布局组件

Android开发⾃学笔记(AndroidStudio)—4.1布局组件⼀、引⾔Android的界⾯是有布局和组件协同完成的,布局好⽐是建筑⾥的框架,⽽组件则相当于建筑⾥的砖⽡。
组件按照布局的要求依次排列,就组成了⽤户所看见的界⾯。
在Android4.0之前,我们通常说Android开发五⼤布局和四⼤组件,这五⼤布局就是:1. LinearLayout 线性布局2. FrameLayout 单帧布局,也有中⽂翻译为帧布局、框架布局。
3. RelativeLayout 相对布局4. AbsoluteLayout 绝对布局5. TableLayout 表格布局⽽在Android4.0之后⼜新增了⼀种GridLayout⽹格布局。
⼆、LinearLayout线性布局线性布局是Android开发中最常见的⼀种布局⽅式,它是按照垂直或者⽔平⽅向来布局,通过“android:orientation”属性可以设置线性布局的⽅向。
属性值有垂直(vertical)和⽔平(horizontal)两种。
线性布局的排列在某⾏或者某列并不会⾃动换⾏或换列,就是说如果采⽤⽔平布局,控件宽度超过屏幕显⽰的话,后⾯的控件都将被隐藏,不会⾃动换⾏。
常⽤的属性有:1. android:orientation:可以设置布局的⽅向2. android:id - 为控件指定相应的ID3. android:text - 指定控件当中显⽰的⽂字,需要注意的是,这⾥尽量使⽤string.xml4. android:gravity - 指定控件的基本位置,⽐如说居中,居右等位置5. android:textSize - 指定控件当中字体的⼤⼩6. android:background - 指定控件所⽤的背景⾊,RGB命名法7. android:layout_width - 指定控件的宽度8. android:layout_height - 指定控件的⾼度9. android:layout_weight - 指定控件的占⽤⽐例10. android:padding - 指定控件的内边距,也就是说控件当中的内容11. android:sigleLine - 如果设置为真的话,则将控件的内容显⽰在⼀⾏当中layout_weight属性以控制各个控件在布局中的相对⼤⼩。
第2章 Android基础界面设计-布局

案例:D0201_Layout/activity_login
2021/10/19
第2章 Android基础界面设计
2021/10/19
第2章 Android基础界面设计
16
2.2 Android基本布局
https:///guide/topics/ui/declaring-layout?hl=zh-cn
内容大纲
LinearLayout:线性布局,子View水平或垂直方向进行排列 FrameLayout:帧布局,子View以左上角为起点堆叠在一起 RelativeLayout:相对布局,子View之间的相对定位进行排列 GridLayout:网格布局,子View以行、列方式进行排列 ConstraintLayout:约束布局,约束方式连接子View布局(第4章)
• 针对控件内的元素,用来控制元素在该控件里的显示位置 • android:gravity="left"和android:text="提交",这时Button上的文字"提交"将会位于Button
的左部 • layout_width或layout_height值需设为match_parent才有效
➢ layout_gravity
2021/10/19
第2章 Android基础界面设计
7
ViewGroup
ViewGroup提供了对其子View的管理功能,包括布局、动画等。子 组件可以是View、也可以是ViewGroup。
2021/10/19
第2章 Android基础界面设计
8
பைடு நூலகம்
2.1 Android布局文件
layout的含义
案例:D0201_Layout/activity_linearlayout_b.xml、 activity_linearlayout_r.xml
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Android应用程序布局(1)2011-07-19 9:56作者:吴秦出处:/skynet/本文的主要内容就是分别介绍以上视图的七种布局显示方式效果及实现,大纲如下:1、View布局概述2、线性布局(Linear Layout)2.1、Tips:android:layout_weight="1"3、相对布局(Relative Layout)4、表格布局(Table Layout)5、列表视图(List View)5.1、一个小的改进5.2、补充说明6、网格视图(Grid View)7 、绝对布局()8、标签布局(Tab Layout)1、view的布局显示概述通过前面的学习我们知道:在一个Android应用程序中,用户界面通过View和ViewGroup对象构建。
Android中有很多种View和ViewGroup,他们都继承自View 类。
View对象是Android平台上表示用户界面的基本单元。
View的布局显示方式直接影响用户界面,View的布局方式是指一组View元素如何布局,准确的说是一个ViewGroup中包含的一些View怎么样布局。
ViewGroup 类是布局(layout)和视图容器(View container)的基类,此类也定义了youtParams类,它作为布局参数的基类,此类告诉父视图其中的子视图想如何显示。
例如,XML布局文件中名为layout_something的属性(参加上篇的4.2节)。
我们要介绍的View的布局方式的类,都是直接或间接继承自ViewGroup类,如下图所示:图1、继承自ViewGroup的一些布局类其实,所有的布局方式都可以归类为ViewGroup的5个类别,即ViewGroup的5个直接子类。
其它的一些布局都扩展自这5个类。
下面分小节分别介绍View的七种布局显示方式。
2、线性布局(Linear Layout)线性布局:是一个ViewGroup以线性方向显示它的子视图(view)元素,即垂直地或水平地。
之前我们的Hello World!程序中view的布局方式就是线性布局的,一定不陌生!如下所示res/layour/main.xml:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/andro id"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="horizontal"><!-- have an eye on ! --><Button android:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello, I am a Button1"android:layout_weight="1"/><Button android:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello, I am a Button2"android:layout_weight="1"/><Button android:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello, I am a Button3"android:layout_weight="1"/><Button android:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello, I am a Button4"android:layout_weight="1"/><Button android:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello, I am a Button5"android:layout_weight="1"/></LinearLayout>从上面可以看出根LinearLayout视图组(ViewGroup)包含5个Button,它的子元素是以线性方式(horizontal,水平的)布局,运行效果如下图所示:图2、线性布局(水平或者说是横向)如果你在android:orientation="horizontal"设置为vertical,则是是垂直或者说是纵向的,如下图所示:图3、线性布局(垂直或者说是纵向)2.1、Tips:android:layout_weight="1"这个属性很关键,如果你没有显示设置它,它默认为0。
把上面布局文件(水平显示的那个)中的这个属性都去掉,运行会得出如下结果:图4、layout_weight属性没有了这个属性,我们本来定义的5个Button运行后却只显示了2个Button,为什么呢??"weight"顾名思义是权重的意思,layout_weight 用于给一个线性布局中的诸多视图的重要程度赋值。
所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空间。
这就不难解释为什么会造成上面的情况了:Button1~Button5都设置了layout_height和layout_width属性为wrap_content即包住文字内容,他们都没有设置layout_weight 属性,即默认为0.,这样Button1和Button2根据需要的内容占据了整个屏幕,别的就显示不了啦!若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。
举个例子:比如说我们在水平方向上有一个文本标签和两个文本编辑元素。
该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。
如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。
如果两个文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,则剩余空间的三分之二分给第一个,三分之一分给第二个(数值越小,重要度越高)。
3、相对布局(Relative Layout)相对布局:是一个ViewGroup以相对位置显示它的子视图(view)元素,一个视图可以指定相对于它的兄弟视图的位置(例如在给定视图的左边或者下面)或相对于RelativeLayout的特定区域的位置(例如底部对齐,或中间偏左)。
相对布局是设计用户界面的有力工具,因为它消除了嵌套视图组。
如果你发现你使用了多个嵌套的LinearLayout视图组后,你可以考虑使用一个RelativeLayout 视图组了。
看下面的res/layour/main.xml:<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="/apk/res/and roid"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:id="@+id/label"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Type here:"/><EditTextandroid:id="@+id/entry"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="@android:drawable/editbox_background"android:layout_below="@id/label"/><!-- have an eye on ! --> <Buttonandroid:id="@+id/ok"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/entry" <!-- have an eye on ! -->android:layout_alignParentRight="true" <!-- have an eye on ! -->android:layout_marginLeft="10dip"android:text="OK"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toLeftOf="@id/ok" <!-- have an eye on ! -->android:layout_alignTop="@id/ok" <!-- have an eye on ! -->android:text="Cancel"/></RelativeLayout>从上面的布局文件我们知道,RelativeLayout视图组包含一个TextView、一个EditView、两个Button,注意标记了<!-- have an eye on ! -->(请注意运行代码的时候,请把这些注释去掉,否则会运行出错,上面加上是为了更加醒目!)的属性,在使用相对布局方式中就是使用这些类似的属性来定位视图到你想要的位置,它们的值是你参照的视图的id。