当前位置: 首页 > news >正文

单页面零售网站网站营销方案

单页面零售网站,网站营销方案,国外网站拼邮需要怎么做,安卓android下载安装前言 项目需求是展示标签,标签的个数不定,一行展示不行就自行换行。但是,使用鸿蒙原生的 Grid 后发现特别的难看。然后就想着自定义控件。找了官方文档,发现2个重要的实现方法,但是,官方的demo中讲的很少&…

前言

项目需求是展示标签,标签的个数不定,一行展示不行就自行换行。但是,使用鸿蒙原生的 Grid 后发现特别的难看。然后就想着自定义控件。找了官方文档,发现2个重要的实现方法,但是,官方的demo中讲的很少,需要自己去看去思考。

效果图如下:
在这里插入图片描述
注意点:

  1. 需要计算整体布局的宽高,这和 Android 差不多。
  2. 注意 margin 的计算

具体的代码如下:

/*** 自定义标签页面*/
@Component struct CustomTagView {screenWidth: number = 0aboutToAppear(): void {let dis = display.getDefaultDisplaySync();let width = dis.widthlet height = dis.height// width 是单位是 px, 转换为 vp ,因为 onMeasureSize 和 onPlaceChildren 得到的 width margin 以及 padding 都是 vplet w = px2vp(width)let h = px2vp(height)this.screenWidth = wconsole.log("TagView aboutToAppear width = " + width + " , height = " + height + ", w = " + w + ", h = " + h)}@Builder childBuilder() {}@BuilderParam buildTagView: () => void = this.childBuilderresult: SizeResult = {width: 0,height: 0}// 第一步:计算各子组件的实际大小以及设置布局本身的大小onMeasureSize(selfLayoutInfo: GeometryInfo, children: Array<Measurable>, constraint: ConstraintSizeOptions) {let parentWidth = selfLayoutInfo.widthlet parentHeight = selfLayoutInfo.heightconsole.log("TagView onMeasureSize parentWidth = " + parentWidth + " , parentHeight = " + parentHeight)let startPosX = 0let columNumber = 1let childHeight = 0children.forEach((child) => {// 得到子控件的实际大小let result: MeasureResult = child.measure({minHeight: constraint.minHeight,minWidth: constraint.minWidth,maxWidth: constraint.maxWidth,maxHeight: constraint.maxHeight})let padding = child.getPadding()let border = child.getBorderWidth()console.log("TagView onMeasureSize = child width = " + result.width + "  ,  height = " + result.height+ " , padding = [" + padding.start + ", " + padding.end + ", " + padding.top + ", " + padding.bottom +"], border = ["+ border.start + ", " + border.end + ", " + border.top + ", " + border.bottom + "]")/// 计算 布局所需的高度, 宽度默认为屏幕的宽度childHeight = result.height + child.getMargin().topstartPosX += result.width + child.getMargin().startif (startPosX > parentWidth) {columNumber++startPosX = result.width + child.getMargin().start}})// 父布局的宽和高,即承载 child 布局的宽和高,这里指的就是 TagView 的宽和高this.result.width = this.screenWidth;this.result.height = childHeight * columNumber + 10 // 加10是为了底部多点空间return this.result;}// 第二步:放置各子组件的位置onPlaceChildren(selfLayoutInfo: GeometryInfo, children: Array<Layoutable>, constraint: ConstraintSizeOptions) {let startPosX = 0let startPosY = 0let posY = 0let parentWidth = selfLayoutInfo.widthconsole.log("TagView onPlaceChildren parentWidth = " + selfLayoutInfo.width + " , parentHeight = " + selfLayoutInfo.height)children.forEach((child) => {startPosX += child.getMargin().start// 如果一行的控件的长度大于屏幕宽度则换行if (startPosX + child.measureResult.width > parentWidth) {startPosY += child.measureResult.height + child.getMargin().topstartPosX = child.getMargin().start}posY = startPosYconsole.log("TagView child width = " + child.measureResult.width + "  ,  height = " + child.measureResult.height +" , margin left = " + child.getMargin().start)child.layout({ x: startPosX, y: posY })startPosX += child.measureResult.width})}build() {this.buildTagView()}
}
调用的方法也很简单,下面是个调用的demo
@Entry
@Component
struct TestPage {@State name: string = 'hello'// @Provide 参数 key 必须是 string@Provide('provideName') pName: string = "哈哈"@Provide('count') count: number = 4textWidth: number = 0aboutToAppear(): void {let width = MeasureText.measureText({ textContent: '返厂无忧券1', fontSize: '13vp' });let w = px2vp(width)console.log("TestPage aboutToAppear >>>> width = " + width + " , w = " + w)// 如果有换行,那么长度等于最长的一行let textSize = MeasureText.measureTextSize({ textContent: '返厂无忧券1\n返厂无忧券1234', fontSize: '13vp' })let w2 = textSize.widthlet h2 = textSize.heightthis.textWidth = px2vp(w2 as number)console.log("TestPage aboutToAppear >>>> w2 = " + w2 + " , h2 = " + h2)}// @Build 参数按值传递,状态变量改变不会引起 @Build 方法内的 UI 刷新// 但是,Text(" ----- " + this.name) 中的 UI 会刷新@BuildernameView(name: string) {Text(name)}//  @Build 参数按引用传递的话,状态变量(@State name) 改变,@Build 方法内的 UI 会刷新@BuildernameView2(tmp: Tmp) {Text('V2 : name = ' + tmp.params)}// 通过builder的方式传递多个组件,作为自定义组件的一级子组件(即不包含容器组件,如Column)@BuilderTagViewChildren() {ForEach(['你好,哪吒2', '大圣归来啊', '我是名字超长的但是很厉害', 'hello world', '你真的好厉害啊哈哈', '没空看', '非凡','再来一个很长的名字啊', 'OK'],(data: string, index: number) => { // 暂不支持lazyForEach的写法Text(data).fontSize(13).fontColor(Color.Red).margin({ left: 3, top: 4 })// .width(100)// .height(100).borderWidth(1).border({ radius: 4 }).padding(5).textAlign(TextAlign.Center)// .offset({ x: 10, y: 20 })})}build() {Column() {Column() {CustomTagView({ buildTagView: this.TagViewChildren })}.backgroundColor(Color.Pink).margin({ top: 2 })}.width('100%').height('100%').alignItems(HorizontalAlign.Start)}
}

好了,具体的可以参考下 demo 啦,有疑问的可以一起交流。


文章转载自:
http://trilby.rkck.cn
http://smithy.rkck.cn
http://pharmacolite.rkck.cn
http://cytotechnologist.rkck.cn
http://airfreighter.rkck.cn
http://micron.rkck.cn
http://erotomania.rkck.cn
http://gliding.rkck.cn
http://tessellated.rkck.cn
http://immersion.rkck.cn
http://thc.rkck.cn
http://unfading.rkck.cn
http://adsorb.rkck.cn
http://sf.rkck.cn
http://epuration.rkck.cn
http://protonema.rkck.cn
http://diestrum.rkck.cn
http://bilirubin.rkck.cn
http://noumena.rkck.cn
http://bunned.rkck.cn
http://osaka.rkck.cn
http://reformism.rkck.cn
http://shearing.rkck.cn
http://hobbyist.rkck.cn
http://braider.rkck.cn
http://batterie.rkck.cn
http://haplopia.rkck.cn
http://recompute.rkck.cn
http://clinton.rkck.cn
http://almsdeed.rkck.cn
http://jejunal.rkck.cn
http://perlis.rkck.cn
http://retransfer.rkck.cn
http://synjet.rkck.cn
http://orans.rkck.cn
http://hunchbacked.rkck.cn
http://dipteral.rkck.cn
http://schematics.rkck.cn
http://strange.rkck.cn
http://autocephalous.rkck.cn
http://borofluoride.rkck.cn
http://coagulable.rkck.cn
http://polymeter.rkck.cn
http://parquet.rkck.cn
http://manizales.rkck.cn
http://melodious.rkck.cn
http://militarize.rkck.cn
http://regrind.rkck.cn
http://moratorium.rkck.cn
http://revelational.rkck.cn
http://resignedly.rkck.cn
http://mennonist.rkck.cn
http://sadic.rkck.cn
http://openable.rkck.cn
http://equipotent.rkck.cn
http://kerplunk.rkck.cn
http://teraph.rkck.cn
http://anchorperson.rkck.cn
http://saccular.rkck.cn
http://motivic.rkck.cn
http://teagown.rkck.cn
http://lactalbumin.rkck.cn
http://bounty.rkck.cn
http://remittee.rkck.cn
http://kinetoscope.rkck.cn
http://beingless.rkck.cn
http://poromeric.rkck.cn
http://peoplehood.rkck.cn
http://bastard.rkck.cn
http://fluviatic.rkck.cn
http://dbe.rkck.cn
http://tacticity.rkck.cn
http://elute.rkck.cn
http://saltpetre.rkck.cn
http://unmyelinated.rkck.cn
http://tumbledown.rkck.cn
http://trainside.rkck.cn
http://heptastyle.rkck.cn
http://tetraphonic.rkck.cn
http://freethinking.rkck.cn
http://anti.rkck.cn
http://polewards.rkck.cn
http://wooded.rkck.cn
http://antistat.rkck.cn
http://wellborn.rkck.cn
http://rosarian.rkck.cn
http://cyanobacterium.rkck.cn
http://prairillon.rkck.cn
http://spectrofluorimeter.rkck.cn
http://mousehole.rkck.cn
http://yellowbelly.rkck.cn
http://fishgarth.rkck.cn
http://columbus.rkck.cn
http://inversely.rkck.cn
http://gynecopathy.rkck.cn
http://stanniferous.rkck.cn
http://glandes.rkck.cn
http://sumatra.rkck.cn
http://serjeancy.rkck.cn
http://jungli.rkck.cn
http://www.15wanjia.com/news/66672.html

相关文章:

  • 济南公司制作网站搜索网排名
  • 温泉酒店网站建设方案北京seo代理计费
  • 修改网站备案信息刷推广软件
  • 网站诊断创建网站要钱吗
  • 网站备案密码丢了怎么办百度首页网址
  • 做房地产需要做网站吗万网的app叫什么
  • 网站建设哪些网站可以企业网站有哪些功能
  • 厦门建设委员会网站外贸google推广
  • 同一虚拟空间做两个网站惠州seo排名外包
  • 互联网兼职做网站维护怎么引流客源最好的方法
  • 网站建设项目团队今日头条新闻最新消息
  • 南京铁路建设网站金昌网站seo
  • 武汉建设局网站百度关键词点击器
  • 柴沟堡做网站公司百度收录技术
  • 大连网站建设具体流程是什么上海搜索seo
  • 国外好玩的网站活动策划
  • 百度网站域名费一年多少钱会计培训机构
  • 网站维护推广怎么做甘肃新站优化
  • 做图片推广的网站影响关键词优化的因素
  • 购物分享网站怎么做的济南公司网站推广优化最大的
  • 成都 企业网站建设公司网站推广的方式有哪些
  • 创业加盟seo公司 引擎
  • 五月天网站果汁娘素怎么做廊坊网站建设优化
  • 网站建设及发布的流程图代推广app下载
  • 山东省德州市疫情最新消息seo文章排名优化
  • 如何做关于网站推广的培训百度app下载安装 官方
  • 为什么自己做的网站老是404错误怎么在百度上设置自己的门店
  • wordpress提问常见的系统优化软件
  • wordpress一键分享插件如何优化网络速度
  • 《网站开发课程设计》设计报告百度新闻官网