当前位置:网站首页>The Summer Challenge realizes a standard layout of Huawei app with openharmony ETS
The Summer Challenge realizes a standard layout of Huawei app with openharmony ETS
2022-06-21 20:48:00 【51CTO】
use OpenHarmony eTS Achieve one Huawei app Standard layout
This article is participating in the starlight project 3.0 – Summer Challenge
Catalog
1. Introduce
Huawei Of app, We can all see that it was designed by heart , Worth learning . If we look carefully Huawei The phone comes with app, We will find all app, Whatever the type app, Its layout structure is a similar structure , This shows that the use of this layout structure can really be very wide , And the experience was great …
Like Huawei's application market app、 Contacts 、 browser 、 Gallery 、 Smart Life app、 music app、 My Huawei 、 Changlian wait , You see , It's all this upper, middle and lower layout structure , Top bar (top+middle)+ Content display area (content)+ Bottom tab bar , that , Today we will work together to implement such a layout .
2. Effect display
DAYU200 Real machine 
Video address
https://ost.51cto.com/show/13842
Simulator


3. Code explanation
3.1 preparation
1). Add one to save image Resources ets file ,resource_const.ets
Why do you do this ,
One is because I found , Sometimes if you use it directly , Sometimes the picture will be confused , The picture is not displayed .
Second, it is convenient to use and change .
2).string.json Defined in the resource file tab Show text
The next step is to get to the point , Create a new one ets page ,tabpage.ets
3.2 Implement a bottom tab bar
1). Import the required components
2). Definition tab Icon and text colors State variables
3). So let's see build() Layout ,
In the outermost layers Column Container layout , And then there was Flex Layout ,top bar ,middle,Content It's all line by line , So use Row Container layout , Take a seat first .
Bottom tab Column use Flex Layout , Every tab use Column Layout ,Column It's up and down 2 layer , One image, A text .
5 individual tab, So each tab Of width Set to 20%, For the sake of beauty , To the outermost Column Set a background picture .

4). Achieve click tab The effect of switching
Defines the of the current operation tab Indexes
5). Define switch tab function switchTab()
Set the current click tab The selection effect of , At the same time, other tab Uncheck the effect . This method can also continue to optimize .
6). Click on tab To set the current operation tab Index and call switchTab() function
3.3 Implement a top toolbar
Because we want to achieve , When sliding up , hide middle The contents of the column , stay top The column shows the reduced version of middle Information .
So define a show_top_title Variable , Used to control the top title The overt and covert , Define a show_mid_title State variable control middle title The overt and covert .
top The column contains a text ( Initially, it does not display ), A search button , An add button , We hope top The operation button of the column can be on the right , So pay attention to the settings
.alignItems(HorizontalAlign.End)
3.4 Achieve one Grid Grid display
1). Analog data list , The data source is NoticeDataModel Simulation data of , The data structure is a notification , Include title and content , For demonstration purposes only .
2).content Layout use Grid Achieve a mesh effect , Use ForEach Traversal notice_list The data of ,
ForEach Pay attention to the use of , The last part , item => item.id) , Generally, unique fields are used to assign values , You can improve the performance of re rendering after changes .
.columnsTemplate(‘1fr 1fr’) Can be controlled Column format , Is shown as 2 Column , It can be 1 Column ,3 Column
| 1 Column | 2 Column | 3 list |
|---|---|---|
![]() | ![]() | ![]() |
3. When you slide up content when , hide middle The content of , Show at the same time top The text content in the column .
onScrollIndex Callback function
4. Think and summarize
4.1 Icon download
1. Provided by Huawei HarmonyOS Icon Library
2. Alibaba vector icon library
4.2 Achieve the acquisition of screen orientation
adopt resourceManager obtain getConfiguration, then config.direction Get screen orientation , This part of the code is HarmonyOS You can get , But in OpenHarmony Cannot be used in .
5. Complete code
The attachment : https://ost.51cto.com/resource/2076
Want to know more about open source , Please visit :
边栏推荐
- SD training 6.21 summary
- SQL教程之6种鲜为人知的 SQL 技术,可帮助您每月节省 100 小时
- Delete the penultimate node - linked list topic
- 如何使用Memcached实现Django项目缓存
- Software testing office tools recommendation - Desktop Calendar
- 某大厂第二轮裁员来袭,套路满满
- client-go gin的简单整合九-Create
- 软件测试办公工具推荐-桌面日历
- How to redeem financial products after the opening date?
- Learn from the old guard on the development of harmonyos: in the name of the father, code force is fully open! Write a section of harmonyos wishing father's Day
猜你喜欢

黄金哪些值得注意的技术:资金管理的重要性

點雲轉深度圖:轉化,保存,可視化

jmeter线程持续时间

M3608升压ic芯片High Efficiency 2.6A Boost DC/DC Convertor

IAR major upgrade, support vs code, St release the first sensor with processing unit

How does the easycvr intelligent edge gateway hardware set power on self start?

Delete the penultimate node - linked list topic

Gartner 网络研讨会 “九问数字化转型” 会后感

点云转深度图:转化,保存,可视化

Harbor高可用集群设计及部署(实操+视频),基于离线安装方式
随机推荐
DO280OpenShift命令及故障排查--访问资源和资源类型
MySQL CentOS installation MySQL L8
【基于合泰HT32F52352的智慧垃圾桶总结】
Big Fish eating Little Fish Games version complète
jmeter线程持续时间
4.3寸触摸屏智能网络中控主机有哪些应用
Xcode插件管理工具Alcatraz
零售数字化起锚阶段,更多地关注的是如何借助数字化的手段对流量进行挖掘和转化
點雲轉深度圖:轉化,保存,可視化
传iPhone 14将全系涨价;TikTok美国用户数据转移到甲骨文,字节无法访问;SeaTunnel 2.1.2发布|极客头条
What is more advantageous than domestic spot silver?
9种改进软件开发过程的策略
某大厂第二轮裁员来袭,套路满满
Kubernetes-23:详解如何将CPU Manager做到游刃有余
National certification -- examination requirements for software evaluators
BTC投资者损失预计达73亿美元!“割肉式”抛售来袭?加密寒冬比预期更冷、更长!
全局负载均衡实现原理
How to distinguish between machine learning and pattern recognition?
什么比国内现货白银更有优势?
Now CDC supports MySQL 5 What time is it? Previously, it seemed that it was 5.7. Today, it is found that the MySQL data source of 5.6 can also be updated in real time


