
回复
广告功能基本上算是每个软件的必备功能之一,常见的除了轮播图,列表之外,就是上下滚动的形式。广告内容不仅支持上下滚动,还需要支持手势操作,以及关闭当前正在预览的广告内容。在 Android 或 iOS 上要想实现这样的功能并不容易,那么在鸿蒙上怎么实现这样的功能呢?本篇文章教你使用最简单的方式实现一个支持上下滚动的广告控件,建议点赞收藏!
Swiper(this.swiperController)
ForEach(this.data, (item: string,index:number) => {
Row() {
Text(item)
.fontColor(0xfff5a51c)
.fontSize(12)
.layoutWeight(1)
Image($r("app.media.service_notice_close"))
.width(16)
.height(16)
.onClick(()=>{
this.data.splice(index,1)
})
}.width(FULL_WIDTH)
.padding({left:20,right:20})
.alignItems(VerticalAlign.Center)
.justifyContent(FlexAlign.Start)
.width(FULL_WIDTH)
.onClick(()=>{
console.log("点击了"+item)
})
}, (item: string) => item)
this.data.splice(index,1) //index 指的是当前位置下标,1代表要删除的个数
.disableSwipe(false) //是否支持手动操作
.autoPlay(true) //是否自动播放
.interval(1000) //播放时间间隔
.vertical(true) //内容上下切换
.indicator(false)
对比 Android 和 iOS 来说,鸿蒙在实现上相对简单,而且支持功能都能够通过组合控件实现,只要理解需求,分析透彻,再复杂的功能都能够实现,基本上满足日常需求。学会的小伙伴快动手试试吧!