1 activity布局初步
  2 LinearLayout 线性布局 就是以一条线的形式就行布局 可以分为直线型和垂直型
  3
  4 <!--
  5         android:id  —— 为控件指定相应的ID
  6         android:text —— 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符串
  7         android:grivity —— 指定控件的基本位置,比如说居中,居右等位置
  8         android:textSize —— 指定控件当中字体的大小
  9         android:background —— 指定该控件所使用的背景色,RGB命名法
 10         android:width —— 指定控件的宽度
 11         android:height —— 指定控件的高度
 12         android:padding* —— 指定控件的内边距,也就是说控件当中的内容
 13         android:sigleLine —— 如果设置为真的话,则将控件的内容在同一行当中进行显示
 14 -->
 15     <TextView
 16         android:id="@+id/firstText"
 17         android:text="第一行"
 18         android:gravity="center_vertical"
 19         android:textSize="35pt"
 20         android:background="#aa0000"
 21         android:layout_width="fill_parent"
 22         android:layout_height="wrap_content"
 23         android:paddingLeft="10dip"
 24         android:paddingTop="20dip"
 25         android:paddingRight="30dip"
 26         android:paddingBottom="40dip"
 27         android:layout_weight="1"
 28         android:singleLine="true"/>
 29     <TextView
 30 -->
 31
 32 LinearLayout嵌套LinearLayout的布局方式
 33 <?xml version="1.0" encoding="utf-8"?>
 34 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 35     android:orientation="vertical"
 36     android:layout_width="fill_parent"
 37     android:layout_height="fill_parent"
 38     >
 39     <LinearLayout
 40         android:orientation="horizontal"
 41         android:layout_width="fill_parent"
 42         android:layout_height="fill_parent"
 43         android:layout_weight="1">
 44         <TextView
 45           android:text="red"
 46           android:gravity="center_horizontal"
 47           android:background="#aa0000"
 48           android:layout_width="wrap_content"
 49           android:layout_height="fill_parent"
 50           android:layout_weight="1"/>
 51       <TextView
 52           android:text="green"
 53           android:gravity="center_horizontal"
 54           android:background="#00aa00"
 55           android:layout_width="wrap_content"
 56           android:layout_height="fill_parent"
 57           android:layout_weight="1"/>
 58       <TextView
 59           android:text="blue"
 60           android:gravity="center_horizontal"
 61           android:background="#0000aa"
 62           android:layout_width="wrap_content"
 63           android:layout_height="fill_parent"
 64           android:layout_weight="1"/>
 65       <TextView
 66           android:text="yellow"
 67           android:gravity="center_horizontal"
 68           android:background="#aaaa00"
 69           android:layout_width="wrap_content"
 70           android:layout_height="fill_parent"
 71           android:layout_weight="1"/>
 72     </LinearLayout>
 73
 74
 75     <LinearLayout
 76         android:orientation="vertical"
 77         android:layout_width="fill_parent"
 78         android:layout_height="fill_parent"
 79         android:layout_weight="1">
 80     <TextView
 81         android:text="row one"
 82         android:textSize="15pt"
 83         android:layout_width="fill_parent"
 84         android:layout_height="wrap_content"
 85         android:layout_weight="1"/>
 86     <TextView
 87         android:text="row two"
 88         android:textSize="15pt"
 89         android:layout_width="fill_parent"
 90         android:layout_height="wrap_content"
 91         android:layout_weight="1"/>
 92     <TextView
 93         android:text="row three"
 94         android:textSize="15pt"
 95         android:layout_width="fill_parent"
 96         android:layout_height="wrap_content"
 97         android:layout_weight="1"/>
 98     <TextView
 99         android:text="row four"
100         android:textSize="15pt"
101         android:layout_width="fill_parent"
102         android:layout_height="wrap_content"
103         android:layout_weight="1"/>
104     </LinearLayout>
105 </LinearLayout>
106
107 ------------------------------------------------------------------------------------------------
108
109 TableLayout表格布局 就是以表格的形式就行布局
110 <?xml version="1.0" encoding="utf-8"?>
111 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
112     android:layout_width="fill_parent"
113     android:layout_height="fill_parent"
114     android:stretchColumns="0">
115     <TableRow>
116         <TextView
117             android:text="@string/row1_column1"
118             android:background="#aa0000"
119             android:padding="3dip" />
120         <TextView
121             android:text="@string/row1_column1"
122             android:padding="3dip"
123             android:gravity="center_horizontal"
124             android:background="#00aa00"
125             ></TextView>
126         <TextView
127             android:text="@string/row1_column2"
128             android:gravity="right"
129             android:background="#0000aa"
130             android:padding="3dip" />
131     </TableRow>
132
133     <TableRow>
134         <TextView
135             android:text="@string/row2_column1"
136             android:padding="3dip" />
137         <TextView
138             android:text="@string/row2_column2"
139             android:gravity="right"
140             android:padding="3dip" />
141     </TableRow>
142 </TableLayout>
143
144
145 LinearLayout和LinearLayout的布局形式
146 android:layout_weight="1",android:layout_weight="1"就是把这个layout分成2份 1表示占其中的一份
147 <?xml version="1.0" encoding="utf-8"?>
148 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
149     android:orientation="vertical" android:layout_width="fill_parent"
150     android:layout_height="fill_parent">
151     <LinearLayout
152         android:orientation="horizontal"
153         android:layout_width="fill_parent"
154         android:layout_height="fill_parent"
155         android:layout_weight="1">
156         <TextView
157             android:text="red"
158             android:gravity="center_horizontal"
159             android:background="#aa0000"
160             android:layout_width="wrap_content"
161             android:layout_height="fill_parent"
162             android:layout_weight="1" />
163         <TextView
164             android:text="green"
165             android:gravity="center_horizontal"
166             android:background="#00aa00"
167             android:layout_width="wrap_content"
168             android:layout_height="fill_parent"
169             android:layout_weight="1" />
170         <TextView
171             android:text="blue"
172             android:gravity="center_horizontal"
173             android:background="#0000aa"
174             android:layout_width="wrap_content"
175             android:layout_height="fill_parent"
176             android:layout_weight="1" />
177         <TextView
178             android:text="yellow"
179             android:gravity="center_horizontal"
180             android:background="#aaaa00"
181             android:layout_width="wrap_content"
182             android:layout_height="fill_parent"
183             android:layout_weight="1" />
184     </LinearLayout>
185
186
187     <LinearLayout
188         android:orientation="horizontal"
189         android:layout_width="fill_parent"
190         android:layout_height="fill_parent"
191         android:layout_weight="1">
192         <TableLayout
193             xmlns:android="http://schemas.android.com/apk/res/android"
194             android:layout_width="fill_parent"
195             android:layout_height="fill_parent"
196             android:stretchColumns="0">
197             <TableRow>
198                 <TextView
199                     android:text="@string/row1_column1"
200                     android:padding="3dip" />
201                 <TextView
202                     android:text="@string/row1_column1"
203                     android:padding="3dip"
204                     android:gravity="center_horizontal">
205                     </TextView>
206                 <TextView
207                     android:text="@string/row1_column2"
208                     android:gravity="right"
209                     android:padding="3dip" />
210             </TableRow>
211
212             <TableRow>
213                 <TextView
214                     android:text="@string/row2_column1"
215                     android:padding="3dip" />
216                 <TextView
217                     android:text="@string/row2_column2"
218                     android:gravity="right"
219                     android:padding="3dip" />
220             </TableRow>
221         </TableLayout>
222     </LinearLayout>
223 </LinearLayout>
224
225
226 --------------------------------------------------------------------------------
227 RelativeLayout相对布局形式 以控件的方位进行布局
228 <?xml version="1.0" encoding="utf-8"?>
229     <!--
230         android:layout_above 将该控件的底部至于给定ID的控件之上
231         android:layout_below 将该控件的顶部至于给定ID的控件之下
232         android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐
233         android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐
234
235         android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline对齐
236         android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘
237         android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐
238         android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐
239         android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐
240
241
242         android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐
243         android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐
244         android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐
245         android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐
246
247         android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央
248         android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
249         android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央
250     -->
251 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
252                 android:layout_width="fill_parent"
253                 android:layout_height="wrap_content"
254                 android:padding="10px" >
255
256     <TextView android:id="@+id/label"
257               android:layout_width="fill_parent"
258               android:layout_height="wrap_content"
259               android:text="Type here:" />
260
261     <EditText android:id="@+id/entry"
262               android:layout_width="fill_parent"
263               android:layout_height="wrap_content"
264               android:background="@android:drawable/editbox_background"
265               android:layout_below="@id/label" />
266
267     <Button android:id="@+id/ok"
268             android:layout_width="wrap_content"
269             android:layout_height="wrap_content"
270             android:layout_below="@id/entry"
271             android:layout_alignParentRight="true"
272             android:layout_marginLeft="10px"
273             android:text="OK" />
274
275     <Button android:layout_width="wrap_content"
276             android:layout_height="wrap_content"
277             android:layout_toLeftOf="@id/ok"
278             android:layout_alignTop="@id/ok"
279             android:text="Cancel" />
280 </RelativeLayout> 

转载于:https://www.cnblogs.com/dchly/archive/2012/12/05/2802610.html

Android 布局相关推荐

  1. android 布局之RelativeLayout(相对布局)

    android 布局分为LinearLayout TableLayout RelativeLayout FreamLayout AbsoluteLayout. 常用的有LinearLayout,Tab ...

  2. android 布局 站位符,基于android布局中的常用占位符介绍

    大家在做布局文件是肯定会遇到过下面的这种情况 填充出现问题,所以需要用到占位符规范填充 汉字常用占位符: android:layout_width="wrap_content" a ...

  3. 在android布局中使用include和merge标签

    在我们开发Android布局时,经常会有很多的布局是相同的,这个时候我们可以通过<include/>和<merge/>标签实现将复杂的布局包含在需要的布局中,减少重复代码的编写 ...

  4. Xamarin Android布局文件没有智能提示

    Xamarin Android布局文件没有智能提示 在Visual Studio 2015中,Android项目的Main.axml文件没有智能提示,不便于布局文件的编写.解决办法: (1)从Xama ...

  5. android表格布局最后一个组件,Android布局之TableLayout表格布局

    Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件.当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列 ...

  6. 下列不属于android布局的是( ),Android软件工程师笔试题(全选择题)【0-1年经验】...

    Android软件工程师笔试题,全选择题,适合0-1年经验的面试者. Android软件工程师笔试题 单选题(共35题) 1.退出 activity 对一些资源以及状态的操作保存,可以在生命周期的哪个 ...

  7. 【IOC 控制反转】Android 布局依赖注入 ( 布局依赖注入步骤 | 布局依赖注入代码示例 )

    文章目录 总结 一.Android 布局依赖注入步骤 二.Android 布局依赖注入示例 1.创建依赖注入库 2.声明注解 3.Activity 基类 4.依赖注入工具类 5.客户端 Activit ...

  8. android 布局权重问题(最近布局经常坑爹)

    android 布局 权重 With layout_weight you can specify a size ratio between multiple views. E.g. you have ...

  9. Android布局文件的布局方式

    Android布局文件的属性值解析说明:   1.android:id [为控件指定相应的ID] 2.android:text [指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xm ...

  10. android布局的作用,Android UI布局经验总结

    如何在Android中动态设置颜色透明?10%20%到100% Android布局分析工具HierarchyView Android使用include/merge/ViewStub优化布局 List的 ...

最新文章

  1. python 打印皮卡丘_Python到底是什么?学姐靠它拿了5个offer
  2. Android dex分包方案 (多dex)
  3. CSS3的box-sizing:向外撑content-box向内挤border-box 外撑的padding算自己的盒子会变大 内挤的padding会缩小自己
  4. 浏览器自动化操作标准--WebDriver
  5. 什么叫轻量瓷_为什么说陶瓷是华夏文明的徽章?
  6. python编程(类的使用)
  7. reply-code=404, reply-text=NOT_FOUND - no exchange
  8. 网络地址转换 NAT
  9. Flink中task之间的数据交换机制
  10. VS2017 Visual Assist X破解方法
  11. 9008刷机教程oppo_OPPO和Realme手机刷机后内部存储不足,无法下载软件
  12. 计算机辅助遥感制图的基本过程,南京信息工程大学2018年遥感原理与应用考研初试大纲...
  13. 程序员须学计算机语言,新手程序员需要学什么编程语言
  14. android xml文件中进行上传图片以及获取图片
  15. Java Vector API的使用测试
  16. 手把手教你5G时代Webview的正确使用姿势,小白也能看明白
  17. 我见众生皆无意,唯有见你动了情(表白日记分享篇)
  18. Ableton Live 10 Suite v10.1.42 WiN-MAC 音乐制作宿主软件
  19. Flutter教程之Flutter 中的磨砂玻璃效果
  20. 【C语言培训2】 前言 C语言程序设计课程介绍

热门文章

  1. MySQL中锁的必要性_MySQL中的锁之一:锁的必要性及分类
  2. mysql 5.1.6 安装包_Centos6 离线安装 MySQL5.5.55-1(附带安装包及 Perl 依赖包)
  3. mongodb插入数据_MongoDB插入
  4. textswitcher_Android TextSwitcher和ImageSwitcher示例教程
  5. Java面试题:热情盛夏,分享Java大厂面试百题
  6. C++基础教程之数组
  7. 盒子模型之边框border
  8. 二叉树转换成森林amp;森林变成二叉树
  9. Minimum edit distance(levenshtein distance)(最小编辑距离)初探
  10. c语言:从标准输入读取几行输入,输入打印到标准输出上,加上行号