HarmonyOS NEXT开发实战教程—搜索页
今天忙里偷闲,分享一个搜索页实现过程,先上效果图:

界面部分比较简单,大体分为导航栏、历史搜索、猜你想搜和热搜榜几个部分,历史搜索采用用户首选项进行存储数据。
导航栏部分相关代码如下:
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开发实战教程—搜索页的更多相关文章
- Swift游戏开发实战教程(霸内部信息大学)
Swift游戏开发实战教程(大学霸内部资料) 试读下载地址:http://pan.baidu.com/s/1sj7DvQH 介绍:本教程是国内第一本Swift游戏开发专向资料. 本教程具体解说记忆配对 ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发4- 后台模板html页面创建
上一篇教程<asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发3-登录模块开发>完成了本项目的登录模块,登录后就需要进入后台管理首页了,需要准备一个后台模 ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发2-Model层建立
上篇(asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发1-准备工作)文章讲解了开发过程中的准备工作,主要创建了项目数据库及项目,本文主要讲解项目M层的实现,M层这里 ...
- 微信小程序-云开发实战教程
微信小程序-云开发实战教程 云函数,云存储,云数据库,云调用 https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/gettin ...
- HBuilder开发App教程06-首页
实战 前面几节基本是一些概念的普及, 正如前面提到的,本教程会以滴石作为范例进行解说, 有兴趣的能够先行下载体验一下.或者下载源代码研究下. 新建项目 打开HBuilder,在项目管理器中右键--新建 ...
- Python开发实战教程(8)-向网页提交获取数据
来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...
- React Native Android原生模块开发实战|教程|心得|怎样创建React Native Android原生模块
尊重版权,未经授权不得转载 本文出自:贾鹏辉的技术博客(http://blog.csdn.net/fengyuzhengfan/article/details/54691503) 告诉大家一个好消息. ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发3-登录模块开发
进行本文之前需要在数据库用户表里面增加一条用户数据,直接手动添加即可,未安全考虑密码一定要使用Md5加密后的,这里提供666666的Md5密文为(c831b04de153469d),本文完成登录模块的 ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发1-准备工作
/****** Object: 新闻表 Script Date: 2017/9/2 星期六 15:11:12 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENT ...
- php扩展开发实战教程(1)
我的开发环境: Ubuntu16.04 apt方式安装的php5.6, apache,mysql等 由于我的本机用的是apt方式安装的php,所以我这里从头开始用最精简的方式,编译安装一个php5.4 ...
随机推荐
- C51基础知识总览
- 启动U盘制作-小白保姆式超详细刷机教程
疑难解答加微信机器人,给它发:进群,会拉你进入八米交流群 机器人微信号:bamibot 简洁版教程访问:https://bbs.8miyun.cn 一.准备工作 需要用到的工具: 1.一台Window ...
- 大数据之路Week08_day02 (Flume的使用举例(从控制台输入数据,从本地打数据到HDFS,从java代码中进行捕获打入到HDFS,flume监控http source))
在使用之前,提供一个大致思想,使用Flume的过程是确定scource类型,channel类型和sink类型,编写conf文件并开启服务,在数据捕获端进行传入数据流入到目的地. 实例一.从控制台打入数 ...
- 一个生成随机颜色的js函数
function getRandomColor(){ let rgb = []; for(let i=0;i<3;++i){ let color = Math.floor(Math.random ...
- 使用watch指令实时监控nvidia显卡状态
当你在训练模型等需要实时检查英伟达显卡状态的时候,使用watch是很好的解决方案 相较于传统的nvidia-smi -l 1指令实时查看的显示效果不好看,watch可以标记处更新的部分,并且是动态刷新 ...
- JMeter 自定义的respCode不是0就报异常
在实际使用中,后台其实已经对异常的进行了处理,response body 返回来的,都是正常的请求响应: 这个时候,则需要通过 respCode 进行判断该请求是否是有效响应. 如响应报文如下: { ...
- ubuntu apt 安装报错:Media change: please insert the disc labeled 'Ubuntu 20.04.5 LTS Focal Fossa - Release amd64 (20220831)' in the drive '/cdrom/' and press [Enter]
前言 如果你在 Ubuntu 上使用 apt 安装软件包时遇到 "Media change: please insert the disc labeled ..." 的错误消息,这 ...
- Mac下打开进入/usr/local等隐藏目录
教程 Mac下/usr/local目录默认是对于Finder是隐藏,如果需要到/usr/local下去,打开Finder,然后使用command+shift+G,在弹出的目录中填写/usr/local ...
- 学习 Docker 如何查看镜像信息?
学习 Docker 如何查看镜像信息? 一.images 命令列出镜像 通过使用如下两个命令,列出本机已有的镜像: docker images 或: docker image ls 如下图所示: 对上 ...
- 再谈MCP协议,看看 MCP 是如何重塑 AI 与外部数据源互动的能力?
Techscribe Central 缩略图由 Techscribe Central 制作和编辑 MCP!!是不是一头雾水?我当时也是这个反应.我也是最近才听说它开始引发关注,然后我发现大多数人根本不 ...