使用Counter实现图片的切换

使用Counter实现图片的切换

HarmonyOS
2024-08-06 18:04:57
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
rhlee
@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)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.

分享
微博
QQ
微信
回复
2024-08-06 19:44:09


相关问题
HarmonyOS 怎么实现网络切换监听?
489浏览 • 1回复 待解决
HarmonyOS 如何实现应用内语言切换
640浏览 • 1回复 待解决
Navigation实现Tabs切换效果
1674浏览 • 1回复 待解决
如何实现上下切换页面间跳转动画
2269浏览 • 0回复 待解决
HarmonyOS 横竖屏切换实现过于繁琐
700浏览 • 1回复 待解决