滚动不到最后一个ListItem,是被list上方的Text组件影响到了,该如何解决?
import promptAction from '@ohos.promptAction'
let customDialogId: number = 0
@Builder
function customDialogBuilder(arr:number[]) {
Column() {
Text("标题")
.textAlign(TextAlign.Start)
.width('100%')
.height(56)
.fontWeight(500)
.fontSize(20)
List({ space: 20, initialIndex: 0 }) {
ForEach(arr, (item: number, index) => {
ListItem() {
Row() {
Text(item.toString()).fontSize(16).fontWeight(500).layoutWeight(1)
}
}.height(48)
}, (item: number) => item.toString())
}
.margin({ top: 16, bottom: 16 })
.listDirection(Axis.Vertical) // 排列方向
.divider({ strokeWidth: 1, color: 0x05000000, startMargin: 24, endMargin: 24 }) // 每行之间的分界线
.edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果
}
.backgroundColor(0xFFFFFF)
.padding({ left: 24, right: 24 })
.borderRadius(24)
}
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
@State arr:number[] = []
aboutToAppear(): void {
for (let i = 0; i < 20; i++) {
this.arr.push(i)
}
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
promptAction.openCustomDialog({
builder: customDialogBuilder.bind(this,this.arr)
}).then((dialogId: number) => {
customDialogId = dialogId
})
})
}
.width('100%')
}
.height('100%')
}
}
弹窗无法实现自适应高度。子窗口可以自适应高度,无法实现动画效果。List与其他组件同级时,会下压List,导致显示异常,需要将List组件设置layoutWeight(1)即可,自适应高度,可以参考如下demo: