今天忙里偷闲,分享一个搜索页实现过程,先上效果图:

界面部分比较简单,大体分为导航栏、历史搜索、猜你想搜和热搜榜几个部分,历史搜索采用用户首选项进行存储数据。

导航栏部分相关代码如下:

Flex({direction:FlexDirection.Row,wrap:FlexWrap.NoWrap,alignItems:ItemAlign.Center}){
Image($r('app.media.back'))
.width(30)
.height(30)
.objectFit(ImageFit.Contain)
Flex({direction:FlexDirection.Row,wrap:FlexWrap.NoWrap,alignItems:ItemAlign.Center}){
TextInput({placeholder:'长款羽绒服',text:this.searchText})
.width('100%')
.placeholderColor(Color.Gray)
.fontSize(14)
.backgroundColor('rgb(226,226,226)')
.enterKeyType(EnterKeyType.Search)
.onChange((str)=>{
this.searchText = str
})
.onSubmit(()=>{
this.saveHistory(this.searchText)
this.searchText = ''
})
Image($r('app.media.scan'))
.width(22)
.height(22)
.margin({left:5})
.constraintSize({minWidth:22})
.objectFit(ImageFit.Contain) Text('搜索')
.width(60)
.height(28)
.backgroundColor(Color.Orange)
.borderRadius(4)
.fontColor(Color.White)
.textAlign(TextAlign.Center)
.fontSize(12)
.margin({left:5})
}
.padding({left:5,right:5})
.width('100%')
.height(34)
.backgroundColor('rgb(226,226,226)')
.borderRadius(8)
.margin({left:5})}
.padding({left:10,right:10})
.width('100%')
.backgroundColor(Color.White).height(45)

历史搜索部分采用Flex布局实现:

Flex({direction:FlexDirection.Row,wrap:FlexWrap.Wrap}){
ForEach(this.hisList,(str:string,index)=>{
Text(str)
.fontColor('#4a4a4a')
.fontSize(12)
.padding({left:6,right:6,top:4,bottom:4})
.borderWidth(1)
.borderColor('rgb(216,216,216)')
.borderStyle(BorderStyle.Solid)
.margin({left:5,top:5})
.textAlign(TextAlign.Center)
.borderRadius(4)
})}

猜你想搜部分,同样使用Flex布局:

Flex({direction:FlexDirection.Row,wrap:FlexWrap.Wrap}){
ForEach(this.guessList,(str:string,index)=>{
Text(str)
.fontColor('#4a4a4a')
.fontSize(15)
.margin({top:6})
.width('50%')
})}

热搜榜部分使用一个Scroll和一个Swiper实现联动效果:

Column(){
Scroll(this.scrollController){
Row({space:30}){
ForEach(this.hotTitleList,(str:string,index)=>{
Text(str)
.fontSize(15)
.fontColor(this.hotIndex == index?Color.Orange:Color.Gray)
.fontWeight(this.hotIndex == index?FontWeight.Bold:FontWeight.Normal)
.onClick(()=>{
this.hotIndex = index
this.swiperController.changeIndex(this.hotIndex,true)
})
})
}
.height(45)
.alignItems(VerticalAlign.Center) }
.scrollable(ScrollDirection.Horizontal)
.scrollBar(BarState.Off) .width('100%') Swiper(this.swiperController){
ForEach(this.hotTitleList,(str:string,index)=>{
Column(){
ForEach(this.hotContentList,(str:string,index)=>{
Row(){
Row(){
Text((index+1).toString())
.fontSize(15)
.fontColor('#4a4a4a')
.fontWeight(FontWeight.Bold)
.width(40)
.textAlign(TextAlign.Center)
Text(str)
.fontSize(15)
.fontColor('#4a4a4a') }
Text('热度100万')
.fontSize(12)
.fontColor(Color.Gray)
}
.width('100%')
.height(40)
.justifyContent(FlexAlign.SpaceBetween)
.alignItems(VerticalAlign.Center)
.borderRadius(10)
.margin({top:8})
.linearGradient({ angle: 90, colors: [[index<3?0xfff8f3:0xf9f9f9, 0.0], [index<4?0xfffbfa:0xfcfcfc, 0.4], [0xffffff, 1.0]] }) })
}
.width('100%')
.alignItems(HorizontalAlign.Start)
}) }
.vertical(false)
.indicator(false)
.loop(false)
.onAnimationEnd((index: number, extraInfo: SwiperAnimationEvent) => { this.hotIndex = index
console.info("index: " + index)
console.info("current offset: " + extraInfo.currentOffset)
const xOffset: number = this.scrollController.currentOffset().xOffset; this.scrollController.scrollTo({ xOffset: index*70, yOffset: 0 })
})}

HarmonyOS NEXT开发实战教程—搜索页的更多相关文章

  1. Swift游戏开发实战教程(霸内部信息大学)

    Swift游戏开发实战教程(大学霸内部资料) 试读下载地址:http://pan.baidu.com/s/1sj7DvQH 介绍:本教程是国内第一本Swift游戏开发专向资料. 本教程具体解说记忆配对 ...

  2. asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发4- 后台模板html页面创建

    上一篇教程<asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发3-登录模块开发>完成了本项目的登录模块,登录后就需要进入后台管理首页了,需要准备一个后台模 ...

  3. asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发2-Model层建立

    上篇(asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发1-准备工作)文章讲解了开发过程中的准备工作,主要创建了项目数据库及项目,本文主要讲解项目M层的实现,M层这里 ...

  4. 微信小程序-云开发实战教程

    微信小程序-云开发实战教程 云函数,云存储,云数据库,云调用 https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/gettin ...

  5. HBuilder开发App教程06-首页

    实战 前面几节基本是一些概念的普及, 正如前面提到的,本教程会以滴石作为范例进行解说, 有兴趣的能够先行下载体验一下.或者下载源代码研究下. 新建项目 打开HBuilder,在项目管理器中右键--新建 ...

  6. Python开发实战教程(8)-向网页提交获取数据

    来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...

  7. React Native Android原生模块开发实战|教程|心得|怎样创建React Native Android原生模块

    尊重版权,未经授权不得转载 本文出自:贾鹏辉的技术博客(http://blog.csdn.net/fengyuzhengfan/article/details/54691503) 告诉大家一个好消息. ...

  8. asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发3-登录模块开发

    进行本文之前需要在数据库用户表里面增加一条用户数据,直接手动添加即可,未安全考虑密码一定要使用Md5加密后的,这里提供666666的Md5密文为(c831b04de153469d),本文完成登录模块的 ...

  9. asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发1-准备工作

    /****** Object: 新闻表 Script Date: 2017/9/2 星期六 15:11:12 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENT ...

  10. php扩展开发实战教程(1)

    我的开发环境: Ubuntu16.04 apt方式安装的php5.6, apache,mysql等 由于我的本机用的是apt方式安装的php,所以我这里从头开始用最精简的方式,编译安装一个php5.4 ...

随机推荐

  1. FreeSql学习笔记——11.LinqToSql

    前言   Linq的强大大家有目共睹,可以以简便的方式对数据集进行复杂操作,LinqToSql经常使用在数据库的联表.分组等查询操作中:FreeSql对LinqToSql的支持通过扩展包FreeSql ...

  2. 永久解决VSCode终端中文乱码问题

    方法如下: 在VSCode中通过打开"文件"--"首选项"--"设置", 然后在"setting.json"中 添加以下 ...

  3. flutter - [03] 运算符&条件表达式

    题记部分 一.算术运算符 var a=13; var b=5; 运算符 说明 示例 结果输出 + 加 print(a+b); 18 - 减 print(a-b); 8 * 乘 print(a*b); ...

  4. 基于Microsoft.Extensions.AI核心库实现RAG应用

    大家好,我是Edison. 之前我们了解 Microsoft.Extensions.AI 和 Microsoft.Extensions.VectorData 两个重要的AI应用核心库.基于对他们的了解 ...

  5. 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统

    我在业余时间开发了一款自己的独立产品:升讯威在线客服与营销系统.陆陆续续开发了几年,从一开始的偶有用户尝试,到如今线上环境和私有化部署均有了越来越多的稳定用户. 随时近来 AI 大模型的火热,越来越多 ...

  6. [Qt 基础-02] QToolButton

    QToolButton 文章目录 QToolButton 简介 1. arrowType 2. autoRaise 3. popupMode 4. toolButtonStyle 注意 信号的连接 样 ...

  7. 大型通用电子制造执行系统(MES)

    ​ 简介: 系统参考西门子MOM智能制造Opcenter工业软件制造执行系统Camstar电子套件人机料法环数据建模业务对象和车间生产执行事务逻辑,采用面向对象分层设计与C#编程开发:包含电子制造企业 ...

  8. Wyn商业智能V8.0 Update1版本发布

    智启未来,Wyn商业智能V8.0 Update1版本深度融合AI技术.工业物联网与数据工程能力,带来三大核心亮点及100+新特性,致力于为企业打造全场景智能分析平台,助力构建从数据加工到智能决策的全链 ...

  9. 记载火狐浏览器下的一次新手级的js解密工作

    警告:该随笔内容仅用于合法范围下的学习,不得用于任何商业和非法用途,不得未经授权转载,否则后果自负. 首先是需要解密的网站:https://www.aqistudy.cn/historydata/mo ...

  10. AI时代:本地运行大模型vllm

    https://docs.vllm.ai/en/latest/index.html 高吞吐量.高内存效率的 LLMs 推理和服务引擎(快速搭建本地大模型,且openAI API 兼容) vLLM is ...