最后
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
支持的XML属性
TableLayout的共有XML属性继承自:Component
TableLayout的自有XML属性见下表:
属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |
---|---|---|---|---|
alignment_type | 对齐方式 | align_edges | 表示TableLayout内的组件按边界对齐。 | ohos:alignment_type=“align_edges” |
align_contents | 表示TableLayout内的组件按边距对齐。 | ohos:alignment_type=“align_contents” | ||
column_count | 列数 | integer类型 | 可以直接设置整型数值,也可以引用integer资源。 | ohos:column_count=“3” ohos:column_count=“$integer:count” |
row_count | 行数 | integer类型 | 可以直接设置整型数值,也可以引用integer资源。 | ohos:row_count=“2” ohos:row_count=“$integer:count” |
orientation | 排列方向 | horizontal | 表示水平方向布局。 | ohos:orientation=“horizontal” |
vertical | 表示垂直方向布局。 | ohos:orientation=“vertical” |
TableLayout的创建
- 在XML中创建TableLayout,示例代码如下:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:background_element="#87CEEB"
ohos:padding="8vp">
</TableLayout>
复制
- 添加子组件
a.在graphic文件夹下创建Text的背景table_text_bg_element.xml,示例代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="5vp"/>
<stroke
ohos:width="1vp"
ohos:color="gray"/>
<solid
ohos:color="#00BFFF"/>
</shape>
复制
b.在TableLayout布局中添加子组件。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:background_element="#87CEEB"
ohos:padding="8vp">
<Text
ohos:height="60vp"
ohos:width="60vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="8vp"
ohos:text="1"
ohos:text_alignment="center"
ohos:text_size="20fp"/>
<Text
ohos:height="60vp"
ohos:width="60vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="8vp"
ohos:text="2"
ohos:text_alignment="center"
ohos:text_size="20fp"/>
<Text
ohos:height="60vp"
ohos:width="60vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="8vp"
ohos:text="3"
ohos:text_alignment="center"
ohos:text_size="20fp"/>
<Text
ohos:height="60vp"
ohos:width="60vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="8vp"
ohos:text="4"
ohos:text_alignment="center"
ohos:text_size="20fp"/>
</TableLayout>
复制
TableLayout默认一列多行
设置行列数
<TableLayout
...
ohos:row_count="2"
ohos:column_count="2">
复制
设置TableLayout的行为2,列为2效果
设置布局排列方向
在XML中设置布局排列方向,以“vertical”为例:
<TableLayout
...
ohos:orientation="vertical">
...
</TableLayout>
复制
设置布局排列方向为“vertical”的效果
设置对齐方式
TableLayout提供两种对齐方式,边距对齐“align_contents”、边界对齐“align_edges”,默认为边距对齐“align_contents”。
- 边距对齐方式
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_content"
ohos:alignment_type="align_contents"
ohos:background_element="$graphic:layout_borderline"
ohos:column_count="3"
ohos:padding="8vp">
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="8vp"
ohos:padding="8vp"
ohos:text="1"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
ohos:text="2"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="32vp"
ohos:padding="8vp"
ohos:text="3"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="32vp"
ohos:padding="8vp"
ohos:text="4"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
ohos:text="5"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="8vp"
ohos:padding="8vp"
ohos:text="6"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
</TableLayout>
复制
边距对齐效果
- 边界对齐方式
将TableLayout的对齐方式修改为边界对齐。
<TableLayout
...
ohos:alignment_type="align_edges">
...
</TableLayout>
复制
边界对齐效果
引用graphic文件夹下的背景资源文件为layout_borderline.xml,示例代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="5vp"/>
<stroke
ohos:width="1vp"
ohos:color="gray"/>
</shape>
复制
设置子组件的行列属性
实现合并单元格的效果
TableLayout合并单元格的效果可以通过设置子组件的行列属性来实现。
设置子组件的行列属性均为2的效果展示
在XML中创建TableLayout,并添加子组件,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_content"
ohos:width="match_content"
ohos:alignment_type="align_edges"
ohos:background_element="$graphic:layout_borderline"
ohos:column_count="3"
ohos:padding="8vp"
ohos:row_count="3">
<Text
ohos:id="$+id:text_one"
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
ohos:text="1"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
ohos:text="2"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
ohos:text="3"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
ohos:text="4"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
ohos:text="5"
ohos:text_alignment="center"
ohos:text_size="14fp"/>
<Text
ohos:height="48vp"
ohos:width="48vp"
ohos:background_element="$graphic:table_text_bg_element"
ohos:margin="16vp"
ohos:padding="8vp"
**这里分享一份由字节前端面试官整理的「2021大厂前端面试手册」,内容囊括Html、CSS、Javascript、Vue、HTTP、浏览器面试题、数据结构与算法。全部整理在下方文档中,共计111道**
### HTML
* HTML5有哪些新特性?
* Doctype作⽤? 严格模式与混杂模式如何区分?它们有何意义?
* 如何实现浏览器内多个标签页之间的通信?
* ⾏内元素有哪些?块级元素有哪些? 空(void)元素有那些?⾏内元 素和块级元素有什么区别?
* 简述⼀下src与href的区别?
* cookies,sessionStorage,localStorage 的区别?
* HTML5 的离线储存的使用和原理?
* 怎样处理 移动端 1px 被 渲染成 2px 问题?
* iframe 的优缺点?
* Canvas 和 SVG 图形的区别是什么?

### JavaScript
**[开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/topics/618166371)**
* 问:0.1 + 0.2 === 0.3 嘛?为什么?
* JS 数据类型
* 写代码:实现函数能够深度克隆基本类型
* 事件流
* 事件是如何实现的?
* new 一个函数发生了什么
* 什么是作用域?
* JS 隐式转换,显示转换
* 了解 this 嘛,bind,call,apply 具体指什么
* 手写 bind、apply、call
* setTimeout(fn, 0)多久才执行,Event Loop
* 手写题:Promise 原理
* 说一下原型链和原型链的继承吧
* 数组能够调用的函数有那些?
* PWA使用过吗?serviceWorker的使用原理是啥?
* ES6 之前使用 prototype 实现继承
* 箭头函数和普通函数有啥区别?箭头函数能当构造函数吗?
* 事件循环机制 (Event Loop)

:实现函数能够深度克隆基本类型
* 事件流
* 事件是如何实现的?
* new 一个函数发生了什么
* 什么是作用域?
* JS 隐式转换,显示转换
* 了解 this 嘛,bind,call,apply 具体指什么
* 手写 bind、apply、call
* setTimeout(fn, 0)多久才执行,Event Loop
* 手写题:Promise 原理
* 说一下原型链和原型链的继承吧
* 数组能够调用的函数有那些?
* PWA使用过吗?serviceWorker的使用原理是啥?
* ES6 之前使用 prototype 实现继承
* 箭头函数和普通函数有啥区别?箭头函数能当构造函数吗?
* 事件循环机制 (Event Loop)
