HarmonyOS list的设置回弹是属性.edgeEffect(EdgeEffect.Spring),怎么设置下拉的高度

HarmonyOS
2024-12-25 13:38:45
302浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

可以通过onScrollFrameBegin设置,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-list-V5#onscrollframebegin9

示例参考:

// xxx.ets
@Entry
@Component
struct ListExample {
  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
  @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。

  build() {
    Column() {
      List({ space: 20, initialIndex: 0 }) {
        ForEach(this.arr, (item: number) => {
          ListItem() {
            Text('' + item)
              .width('100%')
              .height(100)
              .fontSize(16)
              .textAlign(TextAlign.Center)
              .borderRadius(10)
              .backgroundColor(0xFFFFFF)
          }
        }, (item: string) => item)
      }
      .listDirection(Axis.Vertical) // 排列方向
      .scrollBar(BarState.Off)
      .friction(0.6)
      .onScrollFrameBegin((offset: number) => {
        if ((this.listPosition == 0 && offset <= 0) || (this.listPosition == 2 && offset >= 0)) {
          return { offsetRemain: offset / 3 }
        }
        this.listPosition = 1
        return { offsetRemain: offset };
      })
      .onReachStart(() => {
        this.listPosition = 0
      })
      .onReachEnd(() => {
        this.listPosition = 2
      })
      .divider({
        strokeWidth: 2,
        color: 0xFFFFFF,
        startMargin: 20,
        endMargin: 20
      }) // 每行之间的分界线
      .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring
      .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => {
        console.info('first' + firstIndex)
        console.info('last' + lastIndex)
        console.info('center' + centerIndex)
      })
      .width('90%')
    }
    .width('100%')
    .height('100%')
    .backgroundColor(0xDCDCDC)
    .padding({ top: 5 })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 15:07:15
相关问题
HarmonyOS 设置list组件高度
586浏览 • 1回复 待解决
List组件initialIndex属性设置不生效
2959浏览 • 1回复 待解决
HarmonyOS List是否可以设置自适应高度
651浏览 • 1回复 待解决
HarmonyOS Text怎么设置最大高度
630浏览 • 1回复 待解决