文章目录
1-五种布局:linear relative frame table absolute
android布局文件的命名空间 xmlns:android
为了防止属性冲突,制定命名空间。
示例:xmlns:android="http://schemas.android.com/apk/res/android”
示例解析:R.java该文件在res/android目录中
xmlns:android必须以"http://schemas.android.com/apk/res/…”开头,后面的部分定义属性的R.java文件所在的包名。
2-动态设置与布局有关的属性LayoutParams.addRule方法
3-TableLayout布局的stretchColumns属性
4-将布局保存成图像
(1)转化为view
(2)打开view的图像缓存
(3)测量大小和layout定义大小
(4)缓存转输入流转bitmap
(4.4.3.1)将布局保存成图像和对activity截屏
5-权重属性layout_weight的作用
父节点为垂直方向,则子节点分高度。
6-系统默认追加< framelayout >节点包括原布局,那么嵌入标签< merge >的作用
系统在编译< merge >不会产生任意根节点,相当于一个占位符。
7-LayoutInflater的inflate函数用法
LayoutInflater作用是将layout的xml布局文件实例化为View类对象。
获取LayoutInflater的方法有如下三种:
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.main, null);
LayoutInflater inflater = LayoutInflater.from(context); (该方法实质就是第一种方法,可参考源代码)
View layout = inflater.inflate(R.layout.main, null);
LayoutInflater inflater = getLayoutInflater();(在Activity中可以使用,实际上是View子类下window的一个函数)
View layout = inflater.inflate(R.layout.main, null);
View inflate(Context context, int resource, ViewGroup root)方法时,在第三个参数root
inflate方法在第三个参数root不为空时,返回的View就是root,而当root为空时,返回的才是加载的layout的根节点。
如果提供root(不传null)时,返回值其实就是这个root,这个方法就是把xml解析成view之后挂载这个root下。
如果传null(不提供root),返回值也是View,它就是xml布局里面的根节点