263 Star 422 Fork 2.9K

OpenHarmony / arkui_ace_engine

 / 详情

Image控件将objectFit属性设置为ImageFit.Contain时,图片虽然伸缩了,但是还是占据着较大的空间

已完成
缺陷 成员
创建于  
2022-01-28 15:25

【模块名_概率】简要描述:

Image控件将objectFit属性设置为ImageFit.Contain时,图片虽然伸缩了,但是还是占据着较大的空间

【环境信息】:

  • 网络环境:不涉及
  • 硬件开发板型号:不涉及
  • 软件版本信息或tag节点
    IDE:
    DevEco Studio 3.0 Beta2
    Build Version: 3.0.0.800, built on December 30, 2021
    Runtime version: 11.0.13+7-b1751.19 amd64
    VM: Dynamic Code Evolution 64-Bit Server VM by JetBrains s.r.o.
    Windows 10 10.0
    GC: G1 Young Generation, G1 Old Generation
    Memory: 1536M
    Cores: 12
    Registry: external.system.auto.import.disabled=true
    
  • 测试环境:Previewer: 3.1.0.0 beta
  • 其他:无

【预置条件】:

DevEco Studio 3.0 Beta2已安装

【测试步骤】:

运行测试用例代码,观察在预览器上的渲染效果

【预期结果】:

图片伸缩以后,Image控件大小与所显示的图片等大

【实际结果】:

图片伸缩以后,Image控件大小与所显示的图片大

输入图片说明

【恢复手段】:

【出现概率】:问题出现次数/实际测试次数

必现

【定位信息】:

    1. Log、截图、多媒体文件等,所有和问题有关的信息:
@Extend(ListItem) function gutter () {
  .padding(8)
}

@Extend(ListItem) function bug () {
  .borderColor(Color.Red)
  .borderWidth(2)
  .borderStyle(BorderStyle.Dashed)
}

@Extend(ListItem) function right () {
  .borderColor(Color.Green)
  .borderWidth(2)
  .borderStyle(BorderStyle.Dashed)
}

@Entry
@Component
export default struct RowBlank {
  build() {
    List({ space: 8 }) {
      ListItem() {
        Text("Image控件objectFit属性BUG")
          .fontSize(24)
          .fontWeight(FontWeight.Bold)
          .textAlign(TextAlign.Center)
          .padding(8)
          .width('100%')
      }
      .sticky(Sticky.Normal)

      ListItem() {
        Grid() {
          ForEach(Array(12).fill($r("app.media.icon")), (item: Resource) => {
            GridItem() {
              Image(item)
                .backgroundColor(0x00ff00)
                .objectFit(ImageFit.Contain)
            }
            .padding(1)
            .backgroundColor(0xff0000)
          }, (item: Resource) => item.id + "")
        }
        .columnsGap(8)
        .columnsTemplate(Array(6).fill("1fr").join(" "))
        .rowsGap(8)
        .rowsTemplate(Array(2).fill("1fr").join(" "))
      }
      .bug()
      .gutter()
      .width('100%')
    }
    .backgroundColor(0xeeeeee)
    .height('100%')
    .align(Alignment.Top)
  }
}

评论 (4)

youzhi92 创建了缺陷
youzhi92 修改了描述
展开全部操作日志

补充说明,给Image空间设置aspectRatio(1)以后,虽然图片大小虽然正常了。但是Grid高度并没有更新,导致行与行之间存在较大的间隔。

@Extend(ListItem) function gutter () {
  .padding(8)
}

@Extend(ListItem) function bug () {
  .borderColor(Color.Red)
  .borderWidth(2)
  .borderStyle(BorderStyle.Dashed)
}

@Extend(ListItem) function right () {
  .borderColor(Color.Green)
  .borderWidth(2)
  .borderStyle(BorderStyle.Dashed)
}

@Entry
@Component
export default struct RowBlank {
  build() {
    List({ space: 8 }) {
      ListItem() {
        Text("Image控件objectFit属性BUG")
          .fontSize(24)
          .fontWeight(FontWeight.Bold)
          .textAlign(TextAlign.Center)
          .padding(8)
          .width('100%')
      }
      .sticky(Sticky.Normal)

      ListItem() {
        Grid() {
          ForEach(Array(12).fill($r("app.media.icon")), (item: Resource) => {
            GridItem() {
              Image(item)
                .backgroundColor(0x00ff00)
                .objectFit(ImageFit.Contain)
            }
            .padding(1)
            .backgroundColor(0xff0000)
          }, (item: Resource) => item.id + "")
        }
        .columnsGap(8)
        .columnsTemplate(Array(6).fill("1fr").join(" "))
        .rowsGap(8)
        .rowsTemplate(Array(2).fill("1fr").join(" "))
      }
      .bug()
      .gutter()
      .width('100%')

      ListItem() {
        Grid() {
          ForEach(Array(12).fill($r("app.media.icon")), (item: Resource) => {
            GridItem() {
              Image(item)
                .aspectRatio(1)
                .backgroundColor(0x00ff00)
                .objectFit(ImageFit.Contain)
            }
            .padding(1)
            .backgroundColor(0xff0000)
          }, (item: Resource) => item.id + "")
        }
        .columnsGap(8)
        .columnsTemplate(Array(6).fill("1fr").join(" "))
        .rowsGap(8)
        .rowsTemplate(Array(2).fill("1fr").join(" "))
      }
      .bug()
      .gutter()
      .width('100%')
    }
    .backgroundColor(0xeeeeee)
    .height('100%')
    .align(Alignment.Top)
  }
}
luoying_ace 任务状态待办的 修改为已确认
luoying_ace 负责人设置为yangfan229
OpenHarmonyTest 优先级设置为主要

该issue存在两点问题:

  1. grid在高度未设置的情况下默认撑满父容器,与web端以及其他组件对比后,目前修改为采用未设置高度的场景下高度跟随子节点。见PR:
    https://gitee.com/openharmony/ace_ace_engine/pulls/1526

  2. image组件默认放大,目前可以通过image组件的fitOriginalSize设置是否跟随图源大小。

yangfan229 任务状态已确认 修改为验收中
yangfan229 通过openharmony/arkui_ace_engine Pull Request !1526任务状态验收中 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
1
https://gitee.com/openharmony/arkui_ace_engine.git
git@gitee.com:openharmony/arkui_ace_engine.git
openharmony
arkui_ace_engine
arkui_ace_engine

搜索帮助