一,LinearLayout(线性布局)
在一个方向上(垂直或水平)对齐所有子元素
一个垂直列表每行将只有一个子元素(无论它们有多宽)
一个水平列表只是一列的高度(最高子元素的高度来填充)
下面是一个简单的线性布局的例子:
-
01 <?xml version="1.0" encoding="utf-8"?>
-
02 <LinearLayout
-
03 xmlns:android=“http://schemas.android.com/apk/res/android”
-
04 android:layout_width=“match_parent”
-
05 android:layout_height=“match_parent” android:orientation=“vertical”>
-
06 <EditText android:text=“EditText”
-
07
-
08 android:id=“@+id/editText1”
-
09
-
10 android:layout_height=“wrap_content”
-
11
-
12 android:layout_width=“fill_parent”>
-
13
-
14
-
15 <LinearLayout android:id=“@+id/linearLayout1”
-
16
-
17 android:layout_height=“fill_parent”
-
18
-
19 android:layout_width=“fill_parent”
-
20
-
21 android:gravity=“right”>
-
22 <Button android:id=“@+id/button2”
-
23
-
24 android:text=“Button”
-
25
-
26 android:layout_width=“wrap_content”
-
27
-
28 android:layout_height=“wrap_content”>
-
29 <Button android:text=“Button”
-
30
-
31 android:id=“@+id/button1”
-
32
-
33 android:layout_width=“wrap_content”
-
34
-
35 android:layout_height=“wrap_content”>
-
36
-
37
复制代码
最外层布局为垂直线性布局,宽度为整个屏幕(fill_parent),高度为刚好适合子控件(wrap_content)。然后依次添加一个EditText,一个水平布局的LinearLayout,在这个线性布局里面,摆放两个Button,该线性布局的gravity属性设置为”right”,所以里面的两个Button靠右显示。
二,TableLayout(表格布局)
把子元素放入到行与列中
不显示行、列或是单元格边界线
单元格不能横跨行,如HTML中一样
表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象。TableRow可以添加子控件,每添加一个为一列。
android:layout_colum官方解释:The index of the column in which this child should be,也即是设置该控件在TableRow中所处的列。
android:layout_span官方解释:Defines how many columns this child should span,也即是设置该控件所跨越的列数。
android:collapseColumns官方解释:The 0 based index of the columns to collapse. The column indices must be separated by a comma: 1, 2, 5.也即是将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。
android:stretchColumns官方解释:The 0 based index of the columns to stretch. The column indices must be separated by a comma: 1, 2, 5. You can stretch all columns by using the value “*” instead. Note that a column can be marked stretchable and shrinkable at the same time.也即是设置指定的列为可伸展的列,可伸展的列会尽量伸展以填满所有可用的空间,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。
android:shrinkColumns官方解释:The 0 based index of the columns to shrink. The column indices must be separated by a comma: 1, 2, 5. You can shrink all columns by using the value “*” instead. 设置指定的列为可收缩的列。当可收缩的列太宽以至于让其他列显示不全时,会纵向延伸空间。当需要设置多列为可收缩时,将列序号用逗号隔开。
下面用一个例子简单说明TableLayout的用法:
-
01 <?xml version="1.0" encoding="utf-8"?>
-
02 <TableLayout xmlns:android=“http://schemas.android.com/apk/res/android”
-
03 android:layout_width=“fill_parent”
-
04 android:layout_height=“fill_parent”
-
05 android:stretchColumns=“1”>
-
06
-
07 <TextView
-
08 android:layout_column=“1”
-
09 android:padding=“3dip” android:text=“Row1”/>
-
10 <TextView
-
11 android:text=“1”
-
12 android:gravity=“right”
-
13 android:padding=“3dip” />
-
14
-
15 <View
-
16 android:layout_height=“2dip”
-
17 android:background=“#FF909090” />
-
18
-
19 <TextView
-
20 android:text=“*”
-
21 android:padding=“3dip” />
-
22 <TextView
-
23 android:text=“Row12”
-
24 android:padding=“3dip” />
-
25 <TextView
-
26 android:text=“2”
-
27 android:gravity=“right”
-
28 android:padding=“3dip” />
-
29
-
30 <View
-
31 android:layout_height=“2dip”
-
32 android:background=“#FF909090” />
-
33
-
34 <TextView
-
35 android:layout_column=“1”
-
36 android:text=“Row13”
-
37 android:padding=“3dip” />
-
38
-
39
复制代码
三、RelativeLayout(相对布局)
相对布局的子控件会根据它们所设置的参照控件和参数进行相对布局。参照控件可以是父控件,也可以是其它子控件,但是被参照的控件必须要在参照它的控件之前定义。下面是一个简单的例子:
-
01 <?xml version="1.0" encoding="utf-8"?>
-
02 <?xml version="1.0" encoding="utf-8"?>
-
03 <RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
-
04 android:layout_width=“fill_parent”
-
05 android:layout_height=“fill_parent”
-
06 >
-
07 <AnalogClock
-
08 android:id=“@+id/aclock”
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
资源分享
- 最新大厂面试专题
这个题库内容是比较多的,除了一些流行的热门技术面试题,如Kotlin,数据库,Java虚拟机面试题,数组,Framework ,混合跨平台开发,等
- 对应导图的Android高级工程师进阶系统学习视频
最近热门的,NDK,热修复,MVVM,源码等一系列系统学习视频都有!
-EZlBoiQJ-1710566692118)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-wwilAUEZ-1710566692119)]
资源分享
- 最新大厂面试专题
这个题库内容是比较多的,除了一些流行的热门技术面试题,如Kotlin,数据库,Java虚拟机面试题,数组,Framework ,混合跨平台开发,等
[外链图片转存中…(img-r9ZgymF2-1710566692119)]
- 对应导图的Android高级工程师进阶系统学习视频
最近热门的,NDK,热修复,MVVM,源码等一系列系统学习视频都有!
[外链图片转存中…(img-z30sIIA9-1710566692120)]
下载方法:点赞+关注后 点击【Android高级工程师进阶学习】即可领取!