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开发实战教程—淘宝搜索页的更多相关文章
- 学习用java基于webMagic+selenium+phantomjs实现爬虫Demo爬取淘宝搜索页面
由于业务需要,老大要我研究一下爬虫. 团队的技术栈以java为主,并且我的主语言是Java,研究时间不到一周.基于以上原因固放弃python,选择java为语言来进行开发.等之后有时间再尝试pytho ...
- Swift游戏开发实战教程(霸内部信息大学)
Swift游戏开发实战教程(大学霸内部资料) 试读下载地址:http://pan.baidu.com/s/1sj7DvQH 介绍:本教程是国内第一本Swift游戏开发专向资料. 本教程具体解说记忆配对 ...
- JS实现选择菜单栏(配合慕课网淘宝搜索框的课程)
以下是关于实现慕课网淘宝搜索框的JS代码,不过只有选择菜单栏(其余比较容易实现). <!doctype html> <html> <head> <!--在IE ...
- selenium+PhantomJS 抓取淘宝搜索商品
最近项目有些需求,抓取淘宝的搜索商品,抓取的品类还多.直接用selenium+PhantomJS 抓取淘宝搜索商品,快速完成. #-*- coding:utf-8 -*-__author__ =''i ...
- 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 ...
- JS仿淘宝详情页菜单条智能定位效果
类似于淘宝详情页菜单条智能定位 对于每个人来说并不陌生!如下截图所示:红色框的那部分! 基本原理: 是用JS侦听滚动事件,当页面的滚动距离(页面滚动的高度)大于或者等于 "对象"( ...
- Web——在淘宝搜索到看到商品
[摘自]http://blog.renren.com/blog/254459622/799372165 浏览器首先查询DNS服务器,将www.taobao.com转换成ip地址.负载均衡的第一步,将你 ...
- Python开发实战教程(8)-向网页提交获取数据
来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...
随机推荐
- [SDOI2016] 数字配对 题解
发现题目中描述的配对条件可以理解为:\(pc_i-pc_j=1\) 且 \(a_i\bmod a_j=0\),其中 \(pc_i\) 表示 \(a_i\) 的质因数个数. 自然想到以 \(pc\) 奇 ...
- Ansible - [11] Roles
前言 Q1:什么是Roles 在实际生产环境中,会编写大量的playbook文件来实现不同的功能.而且,每个playbook还可能会调用其他文件(变量文件),对于海量的.无规律的文件,管理是个问题.A ...
- ARC165F题解
前言 \(2024.10.19\) 日校测 \(T4\),思维太庙,被薄纱了,遂哭弱,写题解以记之. 简要题意 给你一个长度为 \(2n\) 的序列满足 \(\forall a_i\in[1,n]\) ...
- 基于正则化的图自编码器在推荐算法中的应用 Application of graph auto-encoders based on regularization in recommendation algorithms
引言 看过的每一篇文章,都是对自己的提高.不积跬步无以至千里,不积小流无以成江海,积少成多,做更好的自己. 本文基于2023年4月6日发表于SCIPEERJ COMPUTER SCIENCE(PEER ...
- 通用C++ Makefile
点击查看代码 ///////////////////////////////////////////// CC = g++ CFLAGS=-Wall -O2 TARGET = main SRCS := ...
- 针对N=p^rq分解之初探
针对N=p^r*q分解之初探 论文地址:https://eprint.iacr.org/2015/399.pdf 题目:https://www.nssctf.cn/problem/2016 from ...
- .NET 环境下的三维渲染库 HelixToolkit.SharpDX
1. 引言 在 .NET 生态系统中,三维渲染一直是开发者面临的一个挑战.虽然 WPF 提供了基础的 3D 渲染支持,但性能和功能都较为有限.而 HelixToolkit.SharpDX 作为一款基于 ...
- Netty源码—5.Pipeline和Handler
大纲 1.Pipeline和Handler的作用和构成 2.ChannelHandler的分类 3.几个特殊的ChannelHandler 4.ChannelHandler的生命周期 5.Channe ...
- Vite CVE-2025-30208 安全漏洞
Vite CVE-2025-30208 安全漏洞 一.漏洞概述 CVE-2025-30208 是 Vite(一个前端开发工具提供商)在特定版本中存在的安全漏洞.此漏洞允许攻击者通过特殊的 URL 参数 ...
- ANSYS 启动窗口过大问题解决
方法总结(省流版):选择兼容性下更改高 DPI 设置 => 勾选高DPI 缩放代替 ,且其下对应应用程序选项 1.环境 系统环境:Windows 11 设备情况:分辨率 1920×1080:缩放 ...