中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
使用Counter实现图片的切换
微信扫码分享
@Entry @Component struct Index { @State imageCount: number = 0; private images: Resource[] = [$r('app.media.ic_button_circle_add'), $r('app.media.ic_blank_and_divider'), $r('app.media.ic_select_option_gesture'), $r('app.media.ic_prop_size'), $r('app.media.ic_custom_dialog_voice')] build() { Column() { Counter() { Image(this.images[this.imageCount]) .width(20) .height(20) }.onInc(() => { if (this.imageCount < this.images.length - 1) this.imageCount++; }) .onDec(() => { if (this.imageCount > 0) this.imageCount--; }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }