设置list自适应内容撑起高度,会发现list超出父视图的问题

写了一个list,然后自适应内容撑起高度,最大高度为屏幕的百分之75。当内容撑起到最大高度的时候,滑动list,会发现底部有几个cell滑动不出来,看图层是因为list被撑出父视图。因为list会被撑的跟父视图相同的高度,但是我list上面加了title组建,底部加了个安全区view组建。之后我就改成了相对布局,但是相对布局list一直会报警告,没有设置宽高。

HarmonyOS
2024-10-11 10:54:06
1207浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

list自适应内容可以通过设置LayoutWeight(1)属性来解决

可参考demo:

@Entry  
@Component  
struct Index {  
  @State message: string = 'Hello World';  
  build() {  
    Column(){  
      Column() {  
        Text('12')  
          .fontSize(18)  
          .fontWeight(FontWeight.Regular)  
          .fontColor(Color.Black)  
          .textAlign(TextAlign.Center)  
          .backgroundColor(Color.Blue)  
          .width('100%')  
          .height(100)  
        List({ space: 10 }) {  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Red)  
              .width('100%')  
              .height(100)  
          }  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Orange)  
              .width('100%')  
              .height(100)  
          }  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Yellow)  
              .width('100%')  
              .height(600)  
          }  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Gray)  
              .width('100%')  
              .height(600)  
          }  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Yellow)  
              .width('100%')  
              .height(600)  
          }  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Orange)  
              .width('100%')  
              .height(300)  
          }  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Gray)  
              .width('100%')  
              .height(300)  
          }  
        }  
        .padding({ top: 10, left: 10, bottom: 10, right: 10 })  
        .backgroundColor(Color.Pink)  
        .scrollBar(BarState.Off)  
        .onClick(() => {  
        })  
        .width('100%')  
        .constraintSize({  
          maxHeight: '75%'  
        })  
      }  
      .justifyContent(FlexAlign.End)  
      .layoutWeight(1)  
    }  
    .justifyContent(FlexAlign.End)  
    .backgroundColor('#000000')  
    .width('100%')  
    .height('100%')  
  }  
}  
@Entry  
@Component  
struct Index {  
  @State message: string = 'Hello World';  
  build() {  
    Column(){  
      Column() {  
        Text('12')  
          .fontSize(18)  
          .fontWeight(FontWeight.Regular)  
          .fontColor(Color.Black)  
          .textAlign(TextAlign.Center)  
          .backgroundColor(Color.Blue)  
          .width('100%')  
          .height(100)  
        List({ space: 10 }) {  
          ListItem() {  
            Row()  
              .backgroundColor(Color.Red)  
              .width('100%')  
              .height(100)  
          }  
        }  
        .padding({ top: 10, left: 10, bottom: 10, right: 10 })  
        .backgroundColor(Color.Pink)  
        .scrollBar(BarState.Off)  
        .onClick(() => {  
        })  
        .width('100%')  
        .constraintSize({  
          maxHeight: '75%'  
        })  
      }  
      .justifyContent(FlexAlign.End)  
      .layoutWeight(1)  
    }  
    .justifyContent(FlexAlign.End)  
    .backgroundColor('#000000')  
    .width('100%')  
    .height('100%')  
  }  
}
  • 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.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
分享
微博
QQ
微信
回复
2024-10-11 17:21:34


相关问题
HarmonyOS List高度根据内容自适应
1010浏览 • 1回复 待解决
HarmonyOS List是否可以设置自适应高度
635浏览 • 1回复 待解决
List水平布局如何根据内容自适应高度
1528浏览 • 1回复 待解决
HarmonyOS 自适应组件高度问题
1868浏览 • 1回复 待解决
HarmonyOS web高度自适应内容高度
1165浏览 • 1回复 待解决
HarmonyOS Grid高度根据内容自适应
834浏览 • 1回复 待解决
HarmonyOS Web高度自适应问题
1595浏览 • 1回复 待解决
HarmonyOS 高度自适应问题
1031浏览 • 1回复 待解决
HarmonyOS Grid组件能否自适应内容高度?
661浏览 • 1回复 待解决
HarmonyOS GridItem自适应高度问题
1079浏览 • 1回复 待解决
HarmonyOS Grid自适应高度和拖拽问题
1309浏览 • 1回复 待解决
HarmonyOS 设置list组件高度
586浏览 • 1回复 待解决
HarmonyOS Image 在List自适应大小失败
916浏览 • 1回复 待解决
HarmonyOS web组件自适应高度问题
1796浏览 • 1回复 待解决