您的位置 首页 > 数码极客

“tabtab“tabtabtab官网

本文介绍在鸿蒙应用中TabList和TabLi组件的基本用法。

准备TabList页面布局

在layout目录下创建TabList布局,将其命名为abili。

<?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="; ohos:height="match_parent" ohos:width="match_parent" ohos:orientation="vertical"> <Component ohos:height="0vp" ohos:weight="3" ohos:width="match_parent" /> <DirectionalLayout xmlns:ohos="; ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="center" ohos:orientation="vertical"> <Image ohos:id="$+id:image" ohos:width="match_content" ohos:height="match_content" ohos:layout_alignment="center" ohos:image_src="$media:DevEco" /> <Component ohos:height="20vp" ohos:width="match_parent" /> <Text ohos:id="$+id:text_helloworld" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="Image Tab" ohos:text_color="#007F00" ohos:text_size="100" /> </DirectionalLayout> <Component ohos:height="0vp" ohos:weight="5" ohos:width="match_parent" /> </DirectionalLayout>

布局代码中第7行~第22行的用于生成TabList组件,定义了TabList的基本属性;第23行~第27行用于生成Tab页面的容器,目前还没有具体内容,稍后有具体代码生成。

准备Image页面

Image页面主要包含一个Image文件和简单的文字表示:

<?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="; ohos:height="match_parent" ohos:width="match_parent" ohos:orientation="vertical"> <Component ohos:height="0vp" ohos:weight="3" ohos:width="match_parent" /> <DirectionalLayout xmlns:ohos="; ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="center" ohos:orientation="vertical"> <Component ohos:id="$+id:video_area" ohos:height="300vp" ohos:width="300vp" /> <Component ohos:height="20vp" ohos:width="match_parent" /> <Text ohos:id="$+id:text_helloworld" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="Video Tab" ohos:text_color="#0000FF" ohos:text_size="100" /> </DirectionalLayout> <Component ohos:height="0vp" ohos:weight="5" ohos:width="match_parent" /> </DirectionalLayout>

准备Video页面

Video页面包含一个动画,稍微复杂一些。首先是页面本身::

package com.exam; import com.exam; import o; import o; import o.*; import o.element.FrameAnimationElement; import java.io.Console; public class TablistAbilitySlice extends AbilitySlice { private Component imageContent; private Component videoContent; private FrameAnimationElement frameAnimationElement; @Override public void onstart(Intent intent) { (intent); ); TabList tabList = (TabList) findComponentById); (200); // 设置Tab的宽度 (26); // 设置两个Tab之间的间距 TabLi tab1 = Tab(getContext()); ("Image"); (tab1); TabLi tab2 = Tab(getContext()); ("Video"); (tab2); AbilitySlice slice = this; SelectedListener(new TabLiSelectedListener() { @Override public void onSelected(TabLi tab) { ComponentContainer container = (ComponentContainer) findComponentById); i().equals("Image")) { imageContent = Layou(slice).parse, null, false); con(imageContent); } else { videoContent = Layou(slice).parse, null, false); frameAnimationElement = new FrameAnimationElemen(), Re); Component videoArea = videoCon); videoArea.setBackground(frameAnimationElement); (); con(videoContent); } } @Override public void onUnselected(TabLi tab) { i().equals("Video")) { (); } ComponentContainer container = (ComponentContainer) findComponentById); con(); } @Override public void onReselected(TabLi tab) { ComponentContainer container = (ComponentContainer) findComponentById); i().equals("Image")) { con(imageContent); } else { (); con(videoContent); } } }); //最开始选选择tab1 (tab1); } @Override public void onActive() { (); } @Override public void onForeground(Intent intent) { (intent); } }

这个文件和Image页面区别不大,只是在用Component组件代替了Image组件。而动画的实际内容则是由graphic目录中的anima文件决定:

<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:ohos="; ohos:oneshot="false"> <item ohos:element="$media:video01" ohos:duration="100"/> <item ohos:element="$media:video02" ohos:duration="100"/> <item ohos:element="$media:video03" ohos:duration="100"/> <item ohos:element="$media:video04" ohos:duration="100"/> <item ohos:element="$media:video05" ohos:duration="100"/> <item ohos:element="$media:video06" ohos:duration="100"/> <item ohos:element="$media:video07" ohos:duration="100"/> <item ohos:element="$media:video08" ohos:duration="100"/> <item ohos:element="$media:video09" ohos:duration="100"/> <item ohos:element="$media:video10" ohos:duration="100"/> <item ohos:element="$media:video11" ohos:duration="100"/> </animation-list>

生成TabList画面

TabList的每个Tab页面需要由代码生成,具体参见下面的页面类:

参考文档

代码第22行~第27行分别生成了Image和Video两个Tab页。

第29行~第69行是为TabList的各种事件提供响应。需要响应的处理主要有Tab页选择,Tab页取消选择和Tab重新选择。代码中根据当前选中的Tab页面生成或选择不同的组件。

画面显示如下:

参考文档

TabList和Tab组件

TabList类

Tab Li类

动画开发指导

新书介绍

《实战Python设计模式》是作者最近出版的新书,拜托多多关注!

本书利用Python 的标准GUI 工具包tkinter,通过可执行的示例对23 个设计模式逐个进行说明。这样一方面可以使读者了解真实的软件开发工作中每个设计模式的运用场景和想要解决的问题;另一方面通过对这些问题的解决过程进行说明,让读者明白在编写代码时如何判断使用设计模式的利弊,并合理运用设计模式。

对设计模式感兴趣而且希望随学随用的读者通过本书可以快速跨越从理解到运用的门槛;希望学习Python GUI 编程的读者可以将本书中的示例作为设计和开发的参考;使用Python 语言进行图像分析、数据处理工作的读者可以直接以本书中的示例为基础,迅速构建自己的系统架构。


觉得本文有帮助?请分享给更多人。

关注微信公众号【面向对象思考】轻松学习每一天!

面向对象开发,面向对象思考!

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“tabtab,tabtabtab官网,tabtab下载,tabtab官方下载入口”边界阅读