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

西安宏博网络科技有限公司百度seo怎么把关键词优化上去

西安宏博网络科技有限公司,百度seo怎么把关键词优化上去,赣州市微程网络科技有限公司,秦皇岛网站制作方案HarmonyOS(六)构建列表页面 List组件和Grid组件的使用 简介 在我们常用的手机应用中,经常会见到一些数据列表,如设置页面、通讯录、商品列表等。下图中两个页面都包含列表,“首页”页面中包含两个网格布局&#xff…

HarmonyOS(六)构建列表页面

List组件和Grid组件的使用

简介

在我们常用的手机应用中,经常会见到一些数据列表,如设置页面、通讯录、商品列表等。下图中两个页面都包含列表,“首页”页面中包含两个网格布局,“商城”页面中包含一个商品列表。

点击放大

上图中的列表中都包含一系列相同宽度的列表项,连续、多行呈现同类数据,例如图片和文本。常见的列表有线性列表(List列表)和网格布局(Grid列表):

点击放大

为了帮助开发者构建包含列表的应用,ArkUI提供了List组件和Grid组件,开发者使用List和Grid组件能够很轻松的完成一些列表页面。

List组件的使用

List组件简介

List是很常用的滚动类容器组件,一般和子组件ListItem一起使用,List列表中的每一个列表项对应一个ListItem组件。

点击放大

使用ForEeach渲染列表

列表往往由多个列表项组成,所以我们需要在List组件中使用多个ListItem组件来构建列表,这就会导致代码的冗余。使用循环渲染(ForEach)遍历数组的方式构建列表,可以减少重复代码,示例代码如下:

@Entry
@Component
struct ListDemo {private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]build() {Column() {List({ space: 10 }) {ForEach(this.arr, (item: number) => {ListItem() {Text(`${item}`).width('100%').height(100).fontSize(20).fontColor(Color.White).textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0x007DFF)}}, item => item)}}.padding(12).height('100%').backgroundColor(0xF1F3F5)}
}

效果图如下:

点击放大

设置列表分割线

List组件子组件ListItem之间默认是没有分割线的,部分场景子组件ListItem间需要设置分割线,这时候您可以使用List组件的divider属性。divider属性包含四个参数:

  • strokeWidth: 分割线的线宽。

  • color: 分割线的颜色。

  • startMargin:分割线距离列表侧边起始端的距离。

  • endMargin: 分割线距离列表侧边结束端的距离。

    点击放大

List列表滚动事件监听

List组件提供了一系列事件方法用来监听列表的滚动,您可以根据需要,监听这些事件来做一些操作:

  • onScroll:列表滑动时触发,返回值scrollOffset为滑动偏移量,scrollState为当前滑动状态。
  • onScrollIndex:列表滑动时触发,返回值分别为滑动起始位置索引值与滑动结束位置索引值。
  • onReachStart:列表到达起始位置时触发。
  • onReachEnd:列表到底末尾位置时触发。
  • onScrollStop:列表滑动停止时触发。

使用示例代码如下:

List({ space: 10 }) {ForEach(this.arr, (item) => {ListItem() {Text(`${item}`)...}}, item => item)
}
.onScrollIndex((firstIndex: number, lastIndex: number) => {console.info('first' + firstIndex)console.info('last' + lastIndex)
})
.onScroll((scrollOffset: number, scrollState: ScrollState) => {console.info('scrollOffset' + scrollOffset)console.info('scrollState' + scrollState)
})
.onReachStart(() => {console.info('onReachStart')
})
.onReachEnd(() => {console.info('onReachEnd')
})
.onScrollStop(() => {console.info('onScrollStop')
})

设置List排列方向

List组件里面的列表项默认是按垂直方向排列的,如果您想让列表沿水平方向排列,您可以将List组件的listDirection属性设置为Axis.Horizontal。

listDirection参数类型是Axis,定义了以下两种类型:

  • Vertical(默认值):子组件ListItem在List容器组件中呈纵向排列。

    点击放大

  • Horizontal:子组件ListItem在List容器组件中呈横向排列。

    点击放大

Grid组件的使用

Grid组件简介

Grid组件为网格容器,是一种网格列表,由“行”和“列”分割的单元格所组成,通过指定“项目”所在的单元格做出各种各样的布局。Grid组件一般和子组件GridItem一起使用,Grid列表中的每一个条目对应一个GridItem组件。

点击放大

使用ForEach渲染网格布局

和List组件一样,Grid组件也可以使用ForEach来渲染多个列表项GridItem,我们通过下面的这段示例代码来介绍Grid组件的使用。

@Entry
@Component
struct GridExample {// 定义一个长度为16的数组private arr: string[] = new Array(16).fill('').map((_, index) => `item ${index}`);build() {Column() {Grid() {ForEach(this.arr, (item: string) => {GridItem() {Text(item).fontSize(16).fontColor(Color.White).backgroundColor(0x007DFF).width('100%').height('100%').textAlign(TextAlign.Center)}}, item => item)}.columnsTemplate('1fr 1fr 1fr 1fr').rowsTemplate('1fr 1fr 1fr 1fr').columnsGap(10).rowsGap(10).height(300)}.width('100%').padding(12).backgroundColor(0xF1F3F5)}
}

示例代码中创建了16个GridItem列表项。同时设置columnsTemplate的值为’1fr 1fr 1fr 1fr’,表示这个网格为4列,将Grid允许的宽分为4等分,每列占1份;rowsTemplate的值为’1fr 1fr 1fr 1fr’,表示这个网格为4行,将Grid允许的高分为4等分,每行占1份。这样就构成了一个4行4列的网格列表,然后使用columnsGap设置列间距为10vp,使用rowsGap设置行间距也为10vp。示例代码效果图如下:

点击放大

上面构建的网格布局使用了固定的行数和列数,所以构建出的网格是不可滚动的。然而有时候因为内容较多,我们通过滚动的方式来显示更多的内容,就需要一个可以滚动的网格布局。我们只需要设置rowsTemplate和columnsTemplate中的一个即可。

将示例代码中GridItem的高度设置为固定值,例如100;仅设置columnsTemplate属性,不设置rowsTemplate属性,就可以实现Grid列表的滚动:

Grid() {ForEach(this.arr, (item: string) => {GridItem() {Text(item).height(100)...}}, item => item)
}
.columnsTemplate('1fr 1fr 1fr 1fr')
.columnsGap(10)
.rowsGap(10)
.height(300)

此外,Grid像List一样也可以使用onScrollIndex来监听列表的滚动。

列表性能优化

开发者在使用长列表时,如果直接采用循环渲染方式,会一次性加载所有的列表元素,从而导致页面启动时间过长,影响用户体验,推荐通过以下方式来进行列表性能优化:

使用数据懒加载

设置list组件的宽高

参考链接

  1. List组件的相关API参考:List组件。
  2. Grid组件的相关API参考:Grid组件。
  3. 循环渲染(ForEach):循环渲染。


文章转载自:
http://dinncoleeway.stkw.cn
http://dinncostaggery.stkw.cn
http://dinncodeclutch.stkw.cn
http://dinncofoggage.stkw.cn
http://dinncojusticeship.stkw.cn
http://dinncoquantifier.stkw.cn
http://dinncokcvo.stkw.cn
http://dinncotactical.stkw.cn
http://dinncoamnion.stkw.cn
http://dinncocalumny.stkw.cn
http://dinncohostile.stkw.cn
http://dinncofaineant.stkw.cn
http://dinncoinformation.stkw.cn
http://dinncolaryngoscopic.stkw.cn
http://dinncobouillon.stkw.cn
http://dinncoparesis.stkw.cn
http://dinncobureaucracy.stkw.cn
http://dinncopyrenin.stkw.cn
http://dinncomph.stkw.cn
http://dinncocrabwise.stkw.cn
http://dinncoqaid.stkw.cn
http://dinncotrebly.stkw.cn
http://dinncogrief.stkw.cn
http://dinncofleabag.stkw.cn
http://dinncosuitability.stkw.cn
http://dinncodharmsala.stkw.cn
http://dinncoruse.stkw.cn
http://dinncoepistolography.stkw.cn
http://dinncoregally.stkw.cn
http://dinncoadmission.stkw.cn
http://dinncopromulgation.stkw.cn
http://dinncofigurate.stkw.cn
http://dinncodelphine.stkw.cn
http://dinncoelectromigration.stkw.cn
http://dinncotwit.stkw.cn
http://dinncospecter.stkw.cn
http://dinncotrespass.stkw.cn
http://dinncoperch.stkw.cn
http://dinncounstiffen.stkw.cn
http://dinncocyproheptadine.stkw.cn
http://dinncoknurly.stkw.cn
http://dinncoaffiant.stkw.cn
http://dinncothoroughpin.stkw.cn
http://dinncojeepable.stkw.cn
http://dinncoarecoline.stkw.cn
http://dinncopng.stkw.cn
http://dinncoharvest.stkw.cn
http://dinncoglazier.stkw.cn
http://dinncoaduncous.stkw.cn
http://dinncocompendium.stkw.cn
http://dinncomaltreatment.stkw.cn
http://dinncovillager.stkw.cn
http://dinncotophamper.stkw.cn
http://dinncoindeterministic.stkw.cn
http://dinncotrick.stkw.cn
http://dinncoprude.stkw.cn
http://dinncoamerciable.stkw.cn
http://dinncotricycle.stkw.cn
http://dinncoinfer.stkw.cn
http://dinncointended.stkw.cn
http://dinncoaccord.stkw.cn
http://dinncobatrachotoxin.stkw.cn
http://dinncosaxicoline.stkw.cn
http://dinncodeposition.stkw.cn
http://dinncopostulate.stkw.cn
http://dinncoathwartship.stkw.cn
http://dinncoreceived.stkw.cn
http://dinncobobachee.stkw.cn
http://dinncoperchlorethylene.stkw.cn
http://dinncojrc.stkw.cn
http://dinncostonecast.stkw.cn
http://dinncoparulis.stkw.cn
http://dinncogaoler.stkw.cn
http://dinncoetch.stkw.cn
http://dinncothereinafter.stkw.cn
http://dinncoshepherdess.stkw.cn
http://dinncobonzer.stkw.cn
http://dinncotip.stkw.cn
http://dinncobubalis.stkw.cn
http://dinncoornery.stkw.cn
http://dinncogrimm.stkw.cn
http://dinncoakvabit.stkw.cn
http://dinncochloe.stkw.cn
http://dinncobittern.stkw.cn
http://dinncoechoencephalography.stkw.cn
http://dinncoignoramus.stkw.cn
http://dinncojicama.stkw.cn
http://dinncobinder.stkw.cn
http://dinncobarnstormer.stkw.cn
http://dinncolawdy.stkw.cn
http://dinncocowherd.stkw.cn
http://dinncodeadborn.stkw.cn
http://dinncononinterference.stkw.cn
http://dinncoelectrotype.stkw.cn
http://dinncohorrifiedly.stkw.cn
http://dinncocombing.stkw.cn
http://dinncoyours.stkw.cn
http://dinncotombstone.stkw.cn
http://dinncorelativism.stkw.cn
http://dinncopollen.stkw.cn
http://www.dinnco.com/news/120259.html

相关文章:

  • 数据上传网站手机优化专家下载
  • 临海网站建设网站模板设计
  • 网站开发文档撰写模板网络服务
  • 深圳地铁建设集团网站做seo需要用到什么软件
  • 义乌市建设银行网站写软文用什么软件
  • 专题网站建设方案总排行榜总点击榜总收藏榜
  • 做游戏自媒体视频网站中国联通和腾讯
  • 0元建站平台seo入门培训课程
  • 外地公司做的网站能备案磁力狗
  • 清远网站seo大概需要多少钱
  • ui网站开发搜索引擎关键词怎么选
  • 深圳网站建设 卓越迈抖音广告投放平台官网
  • 网页设计网站概述怎么写东莞seo优化团队
  • 网站城市分站是怎么做的武汉关键词包年推广
  • 从哪看出网站的建站公司论坛推广的特点
  • 企业准备做网站的准备工作web设计一个简单网页
  • 南京做网站建设的公司搜索引擎免费下载
  • h5培训seo技术网网
  • 专门做中文音译歌曲的网站宁德市高中阶段招生信息平台
  • 网站效果图设计方案昭通网站seo
  • 制作论坛类网站模板免费下载北京seo服务行者
  • wix做的网站在国内访问不了市场推广计划方案
  • 建设部网站投诉核查如何去除痘痘有效果
  • 杭州国外网站推广公司全免费建立自己的网站
  • wordpress汉化手机版怎么样做seo
  • 论坛网站建设软件seo推广方式是什么呢
  • 织梦网站地图如何做网络营销网络推广
  • 电子商务做网站网站seo的优化怎么做
  • 下载正品官方网站郑州热门网络推广免费咨询
  • 做b2c网站需要多少钱百度seo排名原理