代码拉取完成,页面将自动刷新
【模块名_概率】简要描述:
Image控件将objectFit属性设置为ImageFit.Contain时,图片虽然伸缩了,但是还是占据着较大的空间
【环境信息】:
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
【预置条件】:
DevEco Studio 3.0 Beta2已安装
【测试步骤】:
运行测试用例代码,观察在预览器上的渲染效果
【预期结果】:
图片伸缩以后,Image控件大小与所显示的图片等大
【实际结果】:
图片伸缩以后,Image控件大小与所显示的图片大
【恢复手段】:
【出现概率】:问题出现次数/实际测试次数
必现
【定位信息】:
@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)
}
}
补充说明,给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)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
该issue存在两点问题:
grid在高度未设置的情况下默认撑满父容器,与web端以及其他组件对比后,目前修改为采用未设置高度的场景下高度跟随子节点。见PR:
https://gitee.com/openharmony/ace_ace_engine/pulls/1526
image组件默认放大,目前可以通过image组件的fitOriginalSize设置是否跟随图源大小。
登录 后才可以发表评论