HarmonyOS 图片预览,通过小图看大图的组件或三方库

HarmonyOS
2024-12-25 11:41:31
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

示例参考如下:

ImageGesture.ets

@Component
export struct ImageGesture {
  @State visible: Visibility = Visibility.None
  build() {
    Stack() {
      Row() {
        Column() {
          Image($r('app.media.icon'))
            .width(100)
            .height(100)
            .onClick(() => {
              console.log("hit me!")
              if ( this.visible== Visibility.Visible) {
                this.visible = Visibility.None
              } else {
                this.visible = Visibility.Visible
              }
            })
        }
        .width('100%')
        .justifyContent(FlexAlign.Center)
        .alignItems(HorizontalAlign.Center)
      }
      .height('100%')

      Text('')
        .onClick(() => {
          if (this.visible == Visibility.Visible) {
            this.visible = Visibility.None
          } else {
            this.visible = Visibility.Visible
          }
        })
        .width('100%')
        .height('100%')
        .backgroundColor(0x000000)
        .visibility(this.visible)

      Column() {
        Image($r('app.media.icon'))
          .width(300)
          .height(300)
          .draggable(false)
          .visibility(this.visible)
      }
    }
  }
}
  • 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.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.

Index.ets

import {ImageGesture} from './ImageGesture'
@Entry
@Component
struct Index {
  build() {
    Column(){
      ImageGesture()
    }
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

手指缩放参考一下链接:https://gitee.com/harmonyos-cases/cases/blob/master/CommonAppDevelopment/feature/imageviewer/README.md

分享
微博
QQ
微信
回复
2024-12-25 15:21:36


相关问题
怎么使用pdfjs三方预览pdf文档
3116浏览 • 1回复 待解决
图片加载三方么?
1782浏览 • 1回复 待解决
HarmonyOS 如何删除三方
990浏览 • 1回复 待解决
三方相机预览demo开发
1644浏览 • 1回复 待解决
如何获取可用三方
2494浏览 • 1回复 待解决
实现弹幕功能三方
1780浏览 • 1回复 待解决
HarmonyOS 三方ImageKnife接口调用
968浏览 • 1回复 待解决
HarmonyOS unity内三方问题
853浏览 • 1回复 待解决
HarmonyOS RN三方适配情况
1358浏览 • 1回复 待解决
HarmonyOS flutter三方支持问题
865浏览 • 1回复 待解决
HarmonyOS mqtt是否有专门三方
1207浏览 • 1回复 待解决
HarmonyOS app 有哪些常用三方
1235浏览 • 1回复 待解决
HarmonyOS 如何检测引入三方权限
1563浏览 • 1回复 待解决
工程中三方怎么clear ?
860浏览 • 1回复 待解决