鸿蒙HarmonyOS开发实战—Java UI框架(TableLayout)_鸿蒙 javaui backgroundmodes

最后

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

支持的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 图形的区别是什么?


![](https://img-blog.csdnimg.cn/img_convert/476288e164f5711c5c11e55a79185bd8.png)



### 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)


![](https://img-blog.csdnimg.cn/img_convert/0ba8bcdea9cbbc7373d2fa90b1951a07.png)



:实现函数能够深度克隆基本类型

*   事件流

*   事件是如何实现的?

*   new 一个函数发生了什么

*   什么是作用域?

*   JS 隐式转换,显示转换

*   了解 this 嘛,bind,call,apply 具体指什么

*   手写 bind、apply、call

*   setTimeout(fn, 0)多久才执行,Event Loop

*   手写题:Promise 原理

*   说一下原型链和原型链的继承吧

*   数组能够调用的函数有那些?

*   PWA使用过吗?serviceWorker的使用原理是啥?

*   ES6 之前使用 prototype 实现继承

*   箭头函数和普通函数有啥区别?箭头函数能当构造函数吗?

*   事件循环机制 (Event Loop)


![](https://img-blog.csdnimg.cn/img_convert/0ba8bcdea9cbbc7373d2fa90b1951a07.png)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值