1e41f4b71Sopenharmony_ci# List 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci列表包含一系列相同宽度的列表项。适合连续、多行呈现同类数据,例如图片和文本。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - 该组件内容区小于一屏时,默认没有回弹效果。需要回弹效果,可以通过edgeEffect属性的options参数进行设置。 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> - List组件[通用属性clip](ts-universal-attributes-sharp-clipping.md)的默认值为true。 12e41f4b71Sopenharmony_ci> 13e41f4b71Sopenharmony_ci> - 要使List处于可编辑模式需配合onItemDelete事件和ListItem的editable属性,即可编辑模式实现删除列表项功能,需满足以下条件(该功能从API9开始废弃): 14e41f4b71Sopenharmony_ci> 15e41f4b71Sopenharmony_ci> - editMode属性设置为true。 16e41f4b71Sopenharmony_ci> 17e41f4b71Sopenharmony_ci> - 绑定onItemDelete事件,且事件回调返回true。 18e41f4b71Sopenharmony_ci> 19e41f4b71Sopenharmony_ci> - ListItem的editable属性设置为true。 20e41f4b71Sopenharmony_ci> 21e41f4b71Sopenharmony_ci> - 实现ListItem拖拽,需满足以下条件: 22e41f4b71Sopenharmony_ci> 23e41f4b71Sopenharmony_ci> - editMode属性设置为true(从API9开始无需设置editMode属性)。 24e41f4b71Sopenharmony_ci> 25e41f4b71Sopenharmony_ci> - 绑定onDragStart事件,且事件回调中返回浮动UI布局。 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci## 子组件 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci仅支持[ListItem](ts-container-listitem.md)、[ListItemGroup](ts-container-listitemgroup.md)子组件,支持渲染控制类型([if/else](../../../quick-start/arkts-rendering-control-ifelse.md)、[ForEach](../../../quick-start/arkts-rendering-control-foreach.md)、[LazyForEach](../../../quick-start/arkts-rendering-control-lazyforeach.md)和[Repeat](../../../quick-start/arkts-new-rendering-control-repeat.md))。 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci> **说明:** 33e41f4b71Sopenharmony_ci> 34e41f4b71Sopenharmony_ci> List的子组件的索引值计算规则: 35e41f4b71Sopenharmony_ci> 36e41f4b71Sopenharmony_ci> 按子组件的顺序依次递增。 37e41f4b71Sopenharmony_ci> 38e41f4b71Sopenharmony_ci> if/else语句中,只有条件成立的分支内的子组件会参与索引值计算,条件不成立的分支内子组件不计算索引值。 39e41f4b71Sopenharmony_ci> 40e41f4b71Sopenharmony_ci> ForEach/LazyForEach/Repeat语句中,会计算展开所有子节点索引值。 41e41f4b71Sopenharmony_ci> 42e41f4b71Sopenharmony_ci> [if/else](../../../quick-start/arkts-rendering-control-ifelse.md)、[ForEach](../../../quick-start/arkts-rendering-control-foreach.md)、[LazyForEach](../../../quick-start/arkts-rendering-control-lazyforeach.md)和[Repeat](../../../quick-start/arkts-new-rendering-control-repeat.md)发生变化以后,会更新子节点索引值。 43e41f4b71Sopenharmony_ci> 44e41f4b71Sopenharmony_ci> ListItemGroup作为一个整体计算一个索引值,ListItemGroup内部的ListItem不计算索引值。 45e41f4b71Sopenharmony_ci> 46e41f4b71Sopenharmony_ci> List子组件visibility属性设置为Hidden或None依然会计算索引值。 47e41f4b71Sopenharmony_ci> 48e41f4b71Sopenharmony_ci> List子组件的visibility属性设置为None时不显示,但该子组件上下的space还会生效。 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci## 接口 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ciList(value?:{space?: number | string, initialIndex?: number, scroller?: Scroller}) 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**参数:** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 64e41f4b71Sopenharmony_ci| ------------ | ------------------------------------------- | ---- | ------------------------------------------------------------ | 65e41f4b71Sopenharmony_ci| space | number \| string | 否 | 子组件主轴方向的间隔。<br/>默认值:0<br/>参数类型为number时单位为vp<br/>**说明:** <br/>设置为负数或者大于等于List内容区长度时,按默认值显示。<br/>space参数值小于List分割线宽度时,子组件主轴方向的间隔取分割线宽度。 | 66e41f4b71Sopenharmony_ci| initialIndex | number | 否 | 设置当前List初次加载时视口起始位置显示的item的索引值。<br/>默认值:0<br/>**说明:** <br/>设置为负数或超过了当前List最后一个item的索引值时视为无效取值,无效取值按默认值显示。 | 67e41f4b71Sopenharmony_ci| scroller | [Scroller](ts-container-scroll.md#scroller) | 否 | 可滚动组件的控制器。用于与可滚动组件进行绑定。<br/>**说明:** <br/>不允许和其他滚动类组件绑定同一个滚动控制对象。 | 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci## 属性 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci除支持[通用属性](ts-universal-attributes-size.md)和[滚动组件通用属性](ts-container-scrollable-common.md#属性)外,还支持以下属性: 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci### listDirection 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_cilistDirection(value: Axis) 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci设置List组件排列方向。 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**参数:** 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 88e41f4b71Sopenharmony_ci| ------ | --------------------------------- | ---- | ------------------------------------------ | 89e41f4b71Sopenharmony_ci| value | [Axis](ts-appendix-enums.md#axis) | 是 | 组件的排列方向。<br/>默认值:Axis.Vertical | 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci### divider 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_cidivider(value: {strokeWidth: Length; color?: ResourceColor; startMargin?: Length; endMargin?: Length;} | null,) 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci设置ListItem分割线样式,默认无分割线。 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ciendMargin + startMargin 超过列宽度后startMargin和endMargin会置0。 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_cistrokeWidth, startMargin和endMargin不支持设置百分比。 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ciList的分割线画在主轴方向两个子组件之间,第一个子组件上方和最后一个子组件下方不会绘制分割线。 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci多列模式下,ListItem与ListItem之间的分割线起始边距从每一列的交叉轴方向起始边开始计算,其他情况从List交叉轴方向起始边开始计算。 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ciListItem设置[多态样式](ts-universal-attributes-polymorphic-style.md)时,被按压的子组件上下的分割线不绘制。 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**参数:** 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 116e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 117e41f4b71Sopenharmony_ci| value | {<br/>strokeWidth: [Length](ts-types.md#length),<br/>color?:[ResourceColor](ts-types.md#resourcecolor),<br/>startMargin?: [Length](ts-types.md#length),<br/>endMargin?: [Length](ts-types.md#length)<br/>} \| null | 是 | ListItem分割线样式。<br/>- strokeWidth: 分割线的线宽。<br/>- color: 分割线的颜色。<br/>默认值:0x08000000<br/>- startMargin: 分割线与列表侧边起始端的距离。<br/>默认值:0,单位:vp<br/>- endMargin: 分割线与列表侧边结束端的距离。<br/>默认值:0,单位:vp | 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci### scrollBar 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciscrollBar(value: BarState) 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci设置滚动条状态。 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**参数:** 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 134e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 135e41f4b71Sopenharmony_ci| value | [BarState](ts-appendix-enums.md#barstate) | 是 | 滚动条状态。<br/>默认值:BarState.Auto<br/>**说明:** <br/>API version 9及以下版本默认值为BarState.Off,API version 10及以上版本的默认值为BarState.Auto。 | 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci### cachedCount 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_cicachedCount(value: number) 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci设置列表中ListItem/ListItemGroup的预加载数量,懒加载场景只会预加载List显示区域外cachedCount的内容,非懒加载场景会全部加载。懒加载、非懒加载都只布局List显示区域+List显示区域外cachedCount的内容。<!--Del-->具体使用可参考[减少应用白块说明](../../../performance/arkts-performance-improvement-recommendation.md#减少应用滑动白块)。<!--DelEnd--> 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ciList设置cachedCount后,显示区域外上下各会预加载并布局cachedCount行ListItem。计算ListItem行数时,会计算ListItemGroup内部的ListItem行数。如果ListItemGroup内没有ListItem,则整个ListItemGroup算一行。 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ciList下嵌套使用LazyForEach,并且LazyForEach下嵌套使用ListItemGroup时,LazyForEach会在List显示区域外上下各会创建cachedCount个ListItemGroup。 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**参数:** 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 156e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------------------- | 157e41f4b71Sopenharmony_ci| value | number | 是 | ListItem/ListItemGroup的预加载数量。<br/>默认值:1<br/>取值范围:[0, +∞) | 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci### cachedCount<sup>14+</sup> 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_cicachedCount(count: number, show: boolean) 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci设置列表中ListItem/ListItemGroup的预加载数量,并配置是否显示预加载节点。 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ciList设置cachedCount后,显示区域外上下各会预加载并布局cachedCount行ListItem。计算ListItem行数时,会计算ListItemGroup内部的ListItem行数。如果ListItemGroup内没有ListItem,则整个ListItemGroup算一行。配合[裁剪](ts-universal-attributes-sharp-clipping.md#clip12)或[内容裁剪](ts-container-scrollable-common.md#clipcontent14)属性可以显示出预加载节点。 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**卡片能力:** 从API version 14开始,该接口支持在ArkTS卡片中使用。 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci**参数:** 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 176e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------- | 177e41f4b71Sopenharmony_ci| count | number | 是 | 预加载的ListItem的数量。<br/>默认值:1 <br/>取值范围:[0, +∞)| 178e41f4b71Sopenharmony_ci| show | boolean | 是 | 被预加载的ListItem是否需要显示。 <br/> 默认值:false | 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci### editMode<sup>(deprecated)</sup> 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_cieditMode(value: boolean) 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci设置当前List组件是否处于可编辑模式。可参考[示例3](#示例3)实现删除选中的list项。 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci从API version9开始废弃不再使用,无替代接口。 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**参数:** 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 193e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------------------- | 194e41f4b71Sopenharmony_ci| value | boolean | 是 | 当前List组件是否处于可编辑模式。<br/>默认值:false | 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci### edgeEffect 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ciedgeEffect(value: EdgeEffect, options?: EdgeEffectOptions) 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci设置边缘滑动效果。 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci**参数:** 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 211e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 212e41f4b71Sopenharmony_ci| value | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | 是 | List组件的边缘滑动效果,支持弹簧效果和阴影效果。<br/>默认值:EdgeEffect.Spring | 213e41f4b71Sopenharmony_ci| options<sup>11+</sup> | [EdgeEffectOptions](ts-container-scrollable-common.md#edgeeffectoptions11对象说明) | 否 | 组件内容大小小于组件自身时,是否开启滑动效果。设置为{ alwaysEnabled: true }会开启滑动效果,{ alwaysEnabled: false }不开启。<br/>默认值:{ alwaysEnabled: false } | 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci### chainAnimation 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_cichainAnimation(value: boolean) 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci设置当前List是否启用链式联动动效,开启后列表滑动以及顶部和底部拖拽时会有链式联动的效果。 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci链式联动效果:List内的ListItem间隔一定距离,该距离可以通过List组件space参数设置,默认为20vp。在手指划动过程中,手指拖动的ListItem是主动对象,相邻的ListItem为从动对象,主动对象驱动从动对象联动,驱动效果遵循弹簧物理动效。 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci链式动效生效后,List的分割线不显示。 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci链式动效生效需要满足以下前提条件: 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci 1、List边缘效果为Spring类型。 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci 2、List没有启用多列模式。 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci**参数:** 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 240e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 241e41f4b71Sopenharmony_ci| value | boolean | 是 | 是否启用链式联动动效。<br/>默认值:false,不启用链式联动。true,启用链式联动。 | 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci### multiSelectable<sup>8+</sup> 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_cimultiSelectable(value: boolean) 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci设置是否开启鼠标框选。 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**参数:** 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 258e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 259e41f4b71Sopenharmony_ci| value | boolean | 是 | 是否开启鼠标框选。<br/>默认值:false,关闭框选。true,开启框选。 | 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci### lanes<sup>9+</sup> 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_cilanes(value: number | LengthConstrain, gutter?: Dimension) 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci设置List组件的布局列数或行数。gutter为列间距,当列数大于1时生效。 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci规则如下: 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci- lanes为指定的数量时,根据指定的数量与List组件的交叉轴尺寸除以列数作为列的宽度。 270e41f4b71Sopenharmony_ci- lanes设置了{minLength,maxLength}时,根据List组件的宽度自适应决定lanes数量(即列数),保证缩放过程中lane的宽度符合{minLength,maxLength}的限制。其中,minLength条件会被优先满足,即优先保证符合ListItem的交叉轴尺寸符合最小限制。 271e41f4b71Sopenharmony_ci- lanes设置了{minLength,maxLength},如果父组件交叉轴方向尺寸约束为无穷大时,固定按一列排列,列宽度按显示区域内最大的ListItem计算。 272e41f4b71Sopenharmony_ci- ListItemGroup在多列模式下也是独占一行,ListItemGroup中的ListItem按照List组件的lanes属性设置值来布局。 273e41f4b71Sopenharmony_ci- lanes设置了{minLength,maxLength}时,计算列数会按照ListItemGroup的交叉轴尺寸计算。当ListItemGroup交叉轴尺寸与List交叉轴尺寸不一致时ListItemGroup中的列数与List中的列数可能不一样。 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**参数:** 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 284e41f4b71Sopenharmony_ci| -------------------- | ------------------------------------------------------------ | ---- | ---------------------------------------- | 285e41f4b71Sopenharmony_ci| value | number \| [LengthConstrain](ts-types.md#lengthconstrain) | 是 | List组件的布局列数或行数。<br/>默认值:1 | 286e41f4b71Sopenharmony_ci| gutter<sup>10+</sup> | [Dimension](ts-types.md#dimension10) | 否 | 列间距。<br />默认值:0 | 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci### alignListItem<sup>9+</sup> 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_cialignListItem(value: ListItemAlign) 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci设置List交叉轴方向宽度大于ListItem交叉轴宽度 * lanes时,ListItem在List交叉轴方向的布局方式。 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci**参数:** 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 303e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- | ---- | ------------------------------------------------------ | 304e41f4b71Sopenharmony_ci| value | [ListItemAlign](#listitemalign9枚举说明) | 是 | 交叉轴方向的布局方式。<br/>默认值:ListItemAlign.Start | 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci### sticky<sup>9+</sup> 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_cisticky(value: StickyStyle) 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci配合[ListItemGroup](ts-container-listitemgroup.md)组件使用,设置ListItemGroup中header和footer是否要吸顶或吸底。sticky属性可以设置为 StickyStyle.Header \| StickyStyle.Footer 以同时支持header吸顶和footer吸底。 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**参数:** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 321e41f4b71Sopenharmony_ci| ------ | ------------------------------------ | ---- | ---------------------------------------------------------- | 322e41f4b71Sopenharmony_ci| value | [StickyStyle](#stickystyle9枚举说明) | 是 | ListItemGroup吸顶或吸底效果。<br/>默认值:StickyStyle.None | 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci### scrollSnapAlign<sup>10+</sup> 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ciscrollSnapAlign(value: ScrollSnapAlign) 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci设置列表项滚动结束对齐效果。 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci只支持ListItem等高情况下,设置列表项滚动结束对齐效果。 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci触控板和鼠标滑动List结束后不支持对齐效果。 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci**参数:** 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 341e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | --------------------------------------------------------- | 342e41f4b71Sopenharmony_ci| value | [ScrollSnapAlign](#scrollsnapalign10枚举说明) | 是 | 列表项滚动结束对齐效果。<br/>默认值:ScrollSnapAlign.NONE | 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci### enableScrollInteraction<sup>10+</sup> 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_cienableScrollInteraction(value: boolean) 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci设置是否支持滚动手势,当设置为false时,无法通过手指或者鼠标滚动,但不影响控制器的滚动接口。 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**参数:** 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 357e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ----------------------------------- | 358e41f4b71Sopenharmony_ci| value | boolean | 是 | 是否支持滚动手势。<br/>默认值:true | 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci### nestedScroll<sup>10+</sup> 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_cinestedScroll(value: NestedScrollOptions) 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci设置向前向后两个方向上的嵌套滚动模式,实现与父组件的滚动联动。 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci**参数:** 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 373e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------- | 374e41f4b71Sopenharmony_ci| value | [NestedScrollOptions](ts-container-scrollable-common.md#nestedscrolloptions10对象说明) | 是 | 嵌套滚动选项。 | 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci### friction<sup>10+</sup> 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_cifriction(value: number | Resource) 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci设置摩擦系数,手动划动滚动区域时生效,只对惯性滚动过程有影响,对惯性滚动过程中的链式效果有间接影响。设置为小于等于0的值时,按默认值处理。 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci**参数:** 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 389e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 390e41f4b71Sopenharmony_ci| value | number \| [Resource](ts-types.md#resource) | 是 | 摩擦系数。<br/>默认值:非可穿戴设备为0.6,可穿戴设备为0.9。<br/>从API version 11开始,非可穿戴设备默认值为0.7。<br/>从API version 12开始,非可穿戴设备默认值为0.75。 | 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci### contentStartOffset<sup>11+</sup> 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_cicontentStartOffset(value: number) 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci设置内容区域起始偏移量。列表滚动到起始位置时,列表内容与列表显示区域边界保留指定距离。 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci**参数:** 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 405e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------------------------------- | 406e41f4b71Sopenharmony_ci| value | number | 是 | 内容区域起始偏移量。<br/>默认值:0<br/>单位:vp | 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci### contentEndOffset<sup>11+</sup> 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_cicontentEndOffset(value: number) 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci设置内容区末尾偏移量。列表滚动到末尾位置时,列表内容与列表显示区域边界保留指定距离。 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci**参数:** 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 421e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------------- | 422e41f4b71Sopenharmony_ci| value | number | 是 | 内容区末尾偏移量。<br/>默认值:0<br/>单位:vp | 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci### childrenMainSize<sup>12+</sup> 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_cichildrenMainSize(value: ChildrenMainSize) 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci设置List组件的子组件在主轴方向的大小信息。 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci**参数:** 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 437e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ------------------------------- | 438e41f4b71Sopenharmony_ci| value | [ChildrenMainSize](ts-container-scrollable-common.md#childrenmainsize12对象说明) | 是 | 1. 作用:<br/>通过ChildrenMainSize对象向List组件准确提供所有子组件在主轴方向的大小信息,能够使List组件在子组件的主轴大小不一致、增删子组件、使用[scrollToIndex](ts-container-scroll.md#scrolltoindex)等场景也能维护自己准确的滑动位置,进而使[scrollTo](ts-container-scroll.md#scrollto)能跳转到准确的指定位置,[currentOffset](ts-container-scroll.md#currentoffset)能够获取到当前准确的滑动位置,内置滚动条能够平滑移动无跳变。<br/>2.使用约束:<br/>(1)提供的主轴方向大小必须与子组件实际在主轴方向的大小一致,子组件在主轴方向大小变化或者增删子组件时都必须通过ChildrenMainSize对象方法通知List组件。<br/>(2)当子组件是ListItemGroup时,需要根据ListItemGroup的列数,ListItemGroup中ListItem在主轴方向的间距,ListItemGroup中header,footer,ListItem的大小准确计算出ListItemGroup整体在主轴方向的大小,并提供给List组件。<br/>(3)如果子组件有ListItemGroup,必须给每一个ListItemGroup也设置childrenMainSize属性,List组件和每一个ListItemGroup组件都要通过childrenMainSize属性接口一对一绑定着一个ChildrenMainSize对象。<br/>(4)多列场景使用LazyForEach生成子组件时,需确保LazyForEach全部生成ListItemGroup组件或者全部生成ListItem组件。 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci### maintainVisibleContentPosition<sup>12+</sup> 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_cimaintainVisibleContentPosition(enabled: boolean) 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci设置显示区域上方插入或删除数据时是否要保持可见内容位置不变。 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci**参数:** 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 453e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 454e41f4b71Sopenharmony_ci| enabled | boolean | 是 | 设置显示区域上方插入或删除数据时是否要保持可见内容位置不变。<br/>默认值:false,显示区域上方插入或删除数据时可见内容位置会跟随变化。 true:显示区域上方插入或删除数据时可见内容位置不变。| 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci> **说明:** 457e41f4b71Sopenharmony_ci> - 只有使用LazyForEach在显示区域外插入或删除数据时,才能保持可见内容位置不变。使用ForEach插入或删除数据或使用LazyForEach重新加载数据时,即使maintainVisibleContentPosition属性设置为true,可见区内容位置也会跟随变化。 458e41f4b71Sopenharmony_ci> - maintainVisibleContentPosition属性设置为true后,在显示区域上方插入或删除数据,会触发onDidScroll、onScrollIndex事件。 459e41f4b71Sopenharmony_ci> - maintainVisibleContentPosition属性设置为true后,在多列场景下,一次插入或删除整行数据,可以保持可见内容位置不变,如果不是插入或删除整行数据,可见内容位置还是会发生变化。 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci## ListItemAlign<sup>9+</sup>枚举说明 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 470e41f4b71Sopenharmony_ci| ------ | ------ | ------------------------- | 471e41f4b71Sopenharmony_ci| Start | 0 | ListItem在List中,交叉轴方向首部对齐。 | 472e41f4b71Sopenharmony_ci| Center | 1 | ListItem在List中,交叉轴方向居中对齐。 | 473e41f4b71Sopenharmony_ci| End | 2 | ListItem在List中,交叉轴方向尾部对齐。 | 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci## StickyStyle<sup>9+</sup>枚举说明 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 484e41f4b71Sopenharmony_ci| ------ | ------ | ---------------------------------- | 485e41f4b71Sopenharmony_ci| None | 0 | ListItemGroup的header不吸顶,footer不吸底。 | 486e41f4b71Sopenharmony_ci| Header | 1 | ListItemGroup的header吸顶,footer不吸底。 | 487e41f4b71Sopenharmony_ci| Footer | 2 | ListItemGroup的footer吸底,header不吸顶。 | 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci## ScrollSnapAlign<sup>10+</sup>枚举说明 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci设置列表项滚动结束对齐效果。 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci左右和上下这种两端对齐的样式:当列表位移至末端,则需要将末端的item完整显示,同时不能露出边界空白区域,此时另一端可以出现不限位对齐的现象。 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci只支持item等高场景限位,不等高场景可能存在不准确的情况。 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 502e41f4b71Sopenharmony_ci| ------ | ------ | ---------------------------------------- | 503e41f4b71Sopenharmony_ci| NONE | 0 | 默认无项目滚动对齐效果。 | 504e41f4b71Sopenharmony_ci| START | 1 | 视图中的第一项将在列表的开头对齐。<br/>**说明:**<br/>当列表位移至末端,需要将末端的item完整显示,可能出现开头不对齐的情况。 | 505e41f4b71Sopenharmony_ci| CENTER | 2 | 视图中的中间项将在列表中心对齐。<br/>**说明:**<br/>顶端和末尾的item都可以在列表中心对齐,列表显示可能露出空白,<br/>第一个或最后一个item会对齐到中间位置。 | 506e41f4b71Sopenharmony_ci| END | 3 | 视图中的最后一项将在列表末尾对齐。<br/>**说明:**<br/>当列表位移至顶端,需要将顶端的item完整显示,可能出现末尾不对齐的情况。 | 507e41f4b71Sopenharmony_ci## CloseSwipeActionOptions<sup>11+</sup>对象说明 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci收起[EXPANDED](ts-container-listitem.md#swipeactionstate11枚举说明)状态[ListItem](ts-container-listitem.md)回调事件集合,用于设置收起动画完成后回调事件。 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 516e41f4b71Sopenharmony_ci| ------- | -------- | ---- | ---------------------- | 517e41f4b71Sopenharmony_ci| onFinish | ()=>void | 否 | 在收起动画完成后触发。 | 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ci## 事件 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci除支持[通用事件](ts-universal-events-click.md)和[滚动组件通用事件](ts-container-scrollable-common.md#事件)外,还支持以下事件: 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci### onItemDelete<sup>(deprecated)</sup> 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_cionItemDelete(event: (index: number) => boolean) 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci当List组件在编辑模式时,点击ListItem右边出现的删除按钮时触发。 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci从API version9开始废弃不再使用,无替代接口。 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**参数:** 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 536e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------ | 537e41f4b71Sopenharmony_ci| index | number | 是 | 被删除的列表项的索引值。 | 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci**返回值:** 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci| 类型 | 说明 | 542e41f4b71Sopenharmony_ci| ------- | -------------- | 543e41f4b71Sopenharmony_ci| boolean | 是否已经删除。 | 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ci### onScrollIndex 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_cionScrollIndex(event: (start: number, end: number, center: number) => void) 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ci有子组件划入或划出List显示区域时触发。计算索引值时,ListItemGroup作为一个整体占一个索引值,不计算ListItemGroup内部ListItem的索引值。 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ciList的边缘效果为弹簧效果时,在List划动到边缘继续划动和松手回弹过程不会触发onScrollIndex事件。 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ci触发该事件的条件:列表初始化时会触发一次,List显示区域内第一个子组件的索引值或最后一个子组件的索引值有变化时会触发。 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci从API version 10开始,List显示区域中间位置子组件变化时也会触发该事件。 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**参数:** 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 566e41f4b71Sopenharmony_ci| -------------------- | ------ | ---- | -------------------------------------- | 567e41f4b71Sopenharmony_ci| start | number | 是 | List显示区域内第一个子组件的索引值 | 568e41f4b71Sopenharmony_ci| end | number | 是 | List显示区域内最后一个子组件的索引值。 | 569e41f4b71Sopenharmony_ci| center<sup>10+</sup> | number | 是 | List显示区域内中间位置子组件的索引值。 | 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci### onReachStart 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_cionReachStart(event: () => void) 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci列表到达起始位置时触发。 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ciList初始化时如果initialIndex为0会触发一次,List滚动到起始位置时触发一次。List边缘效果为弹簧效果时,划动经过起始位置时触发一次,回弹回起始位置时再触发一次。 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ci### onReachEnd 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_cionReachEnd(event: () => void) 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci列表到底末尾位置时触发。 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ciList边缘效果为弹簧效果时,划动经过末尾位置时触发一次,回弹回末尾位置时再触发一次。 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci### onScrollFrameBegin<sup>9+</sup> 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_cionScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number }) 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ci列表开始滑动时触发,事件参数传入即将发生的滑动量,事件处理函数中可根据应用场景计算实际需要的滑动量并作为事件处理函数的返回值返回,列表将按照返回值的实际滑动量进行滑动。 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci当listDirection的值为Axis.Vertical时,返回垂直方向滑动量,当listDirection的值为Axis.Horizontal时,返回水平方向滑动量。 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_ci触发该事件的条件:手指拖动List、List惯性划动时每帧开始时触发;List超出边缘回弹、使用滚动控制器和拖动滚动条的滚动不会触发。 608e41f4b71Sopenharmony_ci 609e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 610e41f4b71Sopenharmony_ci 611e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci**参数:** 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 618e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | -------------------------- | 619e41f4b71Sopenharmony_ci| offset | number | 是 | 即将发生的滑动量,单位vp。 | 620e41f4b71Sopenharmony_ci| state | [ScrollState](#scrollstate枚举说明) | 是 | 当前滑动状态。 | 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci**返回值:** 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ci| 类型 | 说明 | 625e41f4b71Sopenharmony_ci| ------------------------ | -------------------- | 626e41f4b71Sopenharmony_ci| { offsetRemain: number } | 实际滑动量,单位vp。 | 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci### onScrollStart<sup>9+</sup> 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_cionScrollStart(event: () => void) 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci列表滑动开始时触发。手指拖动列表或列表的滚动条触发的滑动开始时,会触发该事件。使用[Scroller](ts-container-scroll.md#scroller)滑动控制器触发的带动画的滑动,动画开始时会触发该事件 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci### onScrollStop 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_cionScrollStop(event: () => void) 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci列表滑动停止时触发。手拖动列表或列表的滚动条触发的滑动,手离开屏幕并且滑动停止时会触发该事件。使用[Scroller](ts-container-scroll.md#scroller)滑动控制器触发的带动画的滑动,动画停止会触发该事件。 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci### onItemMove 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_cionItemMove(event: (from: number, to: number) => boolean) 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci列表元素发生移动时触发。 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci**参数:** 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 665e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- | 666e41f4b71Sopenharmony_ci| from | number | 是 | 移动前索引值。 | 667e41f4b71Sopenharmony_ci| to | number | 是 | 移动后索引值。 | 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci**返回值:** 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci| 类型 | 说明 | 672e41f4b71Sopenharmony_ci| ------- | -------------- | 673e41f4b71Sopenharmony_ci| boolean | 是否已经移动。 | 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci### onItemDragStart<sup>8+</sup> 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_cionItemDragStart(event: (event: ItemDragInfo, itemIndex: number) => ((() => any) \| void)) 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci开始拖拽列表元素时触发。 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_ci**参数:** 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 688e41f4b71Sopenharmony_ci| --------- | --------------------------------------------------------- | ---- | ---------------------- | 689e41f4b71Sopenharmony_ci| event | [ItemDragInfo](ts-container-scrollable-common.md#itemdraginfo对象说明) | 是 | 拖拽点的信息。 | 690e41f4b71Sopenharmony_ci| itemIndex | number | 是 | 被拖拽列表元素索引值。 | 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_ci### onItemDragEnter<sup>8+</sup> 693e41f4b71Sopenharmony_ci 694e41f4b71Sopenharmony_cionItemDragEnter(event: (event: ItemDragInfo) => void) 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci拖拽进入列表元素范围内时触发。 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ci**参数:** 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 705e41f4b71Sopenharmony_ci| ------ | --------------------------------------------------------- | ---- | -------------- | 706e41f4b71Sopenharmony_ci| event | [ItemDragInfo](ts-container-scrollable-common.md#itemdraginfo对象说明) | 是 | 拖拽点的信息。 | 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci### onItemDragMove<sup>8+</sup> 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_cionItemDragMove(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number) => void) 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ci拖拽在列表元素范围内移动时触发。 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ci**参数:** 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 721e41f4b71Sopenharmony_ci| ----------- | --------------------------------------------------------- | ---- | -------------- | 722e41f4b71Sopenharmony_ci| event | [ItemDragInfo](ts-container-scrollable-common.md#itemdraginfo对象说明) | 是 | 拖拽点的信息。 | 723e41f4b71Sopenharmony_ci| itemIndex | number | 是 | 拖拽起始位置。 | 724e41f4b71Sopenharmony_ci| insertIndex | number | 是 | 拖拽插入位置。 | 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci### onItemDragLeave<sup>8+</sup> 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_cionItemDragLeave(event: (event: ItemDragInfo, itemIndex: number) => void) 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci拖拽离开列表元素时触发。 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ci**参数:** 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 739e41f4b71Sopenharmony_ci| --------- | --------------------------------------------------------- | ---- | -------------------------- | 740e41f4b71Sopenharmony_ci| event | [ItemDragInfo](ts-container-scrollable-common.md#itemdraginfo对象说明) | 是 | 拖拽点的信息。 | 741e41f4b71Sopenharmony_ci| itemIndex | number | 是 | 拖拽离开的列表元素索引值。 | 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci### onItemDrop<sup>8+</sup> 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_cionItemDrop(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => void) 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci绑定该事件的列表元素可作为拖拽释放目标,当在列表元素内停止拖拽时触发。 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci跨List拖拽时,当拖拽释放的位置绑定了onItemDrop时会返回true,否则为false。List内部拖拽时,isSuccess为onItemMove事件的返回值。 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**参数:** 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 758e41f4b71Sopenharmony_ci| ----------- | --------------------------------------------------------- | ---- | -------------- | 759e41f4b71Sopenharmony_ci| event | [ItemDragInfo](ts-container-scrollable-common.md#itemdraginfo对象说明) | 是 | 拖拽点的信息。 | 760e41f4b71Sopenharmony_ci| itemIndex | number | 是 | 拖拽起始位置。 | 761e41f4b71Sopenharmony_ci| insertIndex | number | 是 | 拖拽插入位置。 | 762e41f4b71Sopenharmony_ci| isSuccess | boolean | 是 | 是否成功释放 | 763e41f4b71Sopenharmony_ci 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci### onScroll<sup>(deprecated)</sup> 766e41f4b71Sopenharmony_cionScroll(event: (scrollOffset: number, scrollState: [ScrollState](#scrollstate枚举说明)) => void) 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci列表滑动时触发。 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci从API version 12开始废弃不再使用,推荐使用[onDidScroll](ts-container-scrollable-common.md#ondidscroll12)事件替代。 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 773e41f4b71Sopenharmony_ci 774e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci**参数:** 779e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 780e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------| 781e41f4b71Sopenharmony_ci| scrollOffset | number | 是 | 每帧滚动的偏移量,List的内容向上滚动时偏移量为正,向下滚动时偏移量为负。<br/>单位vp。 | 782e41f4b71Sopenharmony_ci| scrollState | [ScrollState](ts-container-list.md#scrollstate枚举说明) | 是 | 当前滑动状态。 | 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ci### onScrollVisibleContentChange<sup>12+</sup> 785e41f4b71Sopenharmony_cionScrollVisibleContentChange(handler: OnScrollVisibleContentChangeCallback) 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci有子组件划入或划出List显示区域时触发。计算触发条件时,每一个ListItem、ListItemGroup中的header或footer都算一个子组件。 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ciList的边缘效果为弹簧效果时,在List划动到边缘继续划动和松手回弹过程不会触发onScrollVisibleContentChange事件。 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_ci触发该事件的条件:列表初始化时会触发一次,List显示区域内第一个子组件的索引值或最后一个子组件的索引值有变化时会触发。 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 796e41f4b71Sopenharmony_ci 797e41f4b71Sopenharmony_ci**参数:** 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 800e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------| 801e41f4b71Sopenharmony_ci| handler | [OnScrollVisibleContentChangeCallback](#onscrollvisiblecontentchangecallback12) | 是 | 当前显示内容发生改变的时候触发回调。 | 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci## ScrollState枚举说明 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 808e41f4b71Sopenharmony_ci 809e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 812e41f4b71Sopenharmony_ci| ------ | ------ | ---------------------------------------- | 813e41f4b71Sopenharmony_ci| Idle | 0 | 空闲状态。滚动状态回归空闲时触发,控制器提供的无动画方法控制滚动时触发。 | 814e41f4b71Sopenharmony_ci| Scroll | 1 | 滚动状态。手指拖动List,拖动滚动条和滚动鼠标滚轮时触发。| 815e41f4b71Sopenharmony_ci| Fling | 2 | 惯性滚动状态。动画控制的滚动都会触发。包括快速划动松手后的惯性滚动, <br/>划动到边缘回弹的滚动,快速拖动内置滚动条松手后的惯性滚动, <br/>使用滚动控制器提供的带动画的方法控制的滚动。 | 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci## ListScroller<sup>11+</sup>对象说明 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ciList组件的滚动控制器,通过它控制List组件的滚动,仅支持一对一绑定到List组件。 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci> **说明:** 824e41f4b71Sopenharmony_ci> 825e41f4b71Sopenharmony_ci> ListScroller继承自[Scroller](ts-container-scroll.md#scroller),具有[Scroller](ts-container-scroll.md#scroller)的全部方法。 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ci### 导入对象 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci``` 831e41f4b71Sopenharmony_cilistScroller: ListScroller = new ListScroller() 832e41f4b71Sopenharmony_ci``` 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci### getItemRectInGroup<sup>11+</sup> 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_cigetItemRectInGroup(index: number, indexInGroup: number): RectResult 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci获取[ListItemGroup](ts-container-listitemgroup.md)中的[ListItem](ts-container-listitem.md)的大小和相对于List的位置。 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci**参数:** 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 848e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----------------- | 849e41f4b71Sopenharmony_ci| index | number | 是 | ListItemGroup在List中的索引值。 | 850e41f4b71Sopenharmony_ci| indexInGroup | number | 是 | ListItem在ListItemGroup中的索引值。 | 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci> **说明:** 853e41f4b71Sopenharmony_ci> 854e41f4b71Sopenharmony_ci> - index必须是当前显示区域显示的子组件的索引值,否则视index为非法值。 855e41f4b71Sopenharmony_ci> - 索引值为index的子组件必须是ListItemGroup,否则视index为非法值。 856e41f4b71Sopenharmony_ci> - indexInGroup必须是当前显示区域内ListItemGroup中显示的ListItem的索引值,否则视indexInGroup为非法值。 857e41f4b71Sopenharmony_ci> - index或者indexInGroup为非法值时返回的大小和位置均为0。 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ci**返回值:** 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci| 类型 | 说明 | 862e41f4b71Sopenharmony_ci| ------------------- | -------- | 863e41f4b71Sopenharmony_ci| [RectResult](ts-types.md#rectresult10) | ListItemGroup中的ListItem的大小和相对于List的位置。<br/>单位:vp。 | 864e41f4b71Sopenharmony_ci 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci**错误码**: 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../../errorcode-universal.md)。 869e41f4b71Sopenharmony_ci 870e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 871e41f4b71Sopenharmony_ci| ------- | -------- | 872e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 873e41f4b71Sopenharmony_ci| 100004 | Controller not bound to component. | 874e41f4b71Sopenharmony_ci### getVisibleListContentInfo<sup>13+</sup> 875e41f4b71Sopenharmony_ci 876e41f4b71Sopenharmony_cigetVisibleListContentInfo(x:number, y: number): VisibleListContentInfo 877e41f4b71Sopenharmony_ci 878e41f4b71Sopenharmony_ci根据坐标获取子组件的索引信息。 879e41f4b71Sopenharmony_ci 880e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 883e41f4b71Sopenharmony_ci 884e41f4b71Sopenharmony_ci**参数:** 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 887e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----------------- | 888e41f4b71Sopenharmony_ci| x | number | 是 | x轴坐标,单位为vp。 | 889e41f4b71Sopenharmony_ci| y | number | 是 | y轴坐标,单位为vp。 | 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci> **说明:** 892e41f4b71Sopenharmony_ci> 893e41f4b71Sopenharmony_ci> x或y为非法值时返回的 [VisibleListContentInfo](#visiblelistcontentinfo12对象说明)对象中index为-1,itemGroupArea返回undefined,itemIndexInGroup返回undefined。 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci**返回值:** 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_ci| 类型 | 说明 | 898e41f4b71Sopenharmony_ci| ------------------- | -------- | 899e41f4b71Sopenharmony_ci| [VisibleListContentInfo](#visiblelistcontentinfo12对象说明) | 获得子组件的索引信息。 | 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci**错误码**: 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../../errorcode-universal.md)。 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 906e41f4b71Sopenharmony_ci| ------- | -------- | 907e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 908e41f4b71Sopenharmony_ci| 100004 | Controller not bound to component. | 909e41f4b71Sopenharmony_ci### scrollToItemInGroup<sup>11+</sup> 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ciscrollToItemInGroup(index: number, indexInGroup: number, smooth?: boolean, align?: ScrollAlign): void 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci滑动到指定的ListItemGroup中指定的ListItem。 914e41f4b71Sopenharmony_ci 915e41f4b71Sopenharmony_ci开启smooth动效时,会对经过的所有item进行加载和布局计算,当大量加载item时会导致性能问题。 916e41f4b71Sopenharmony_ci 917e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ci**参数:** 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 924e41f4b71Sopenharmony_ci| --------------------- | -------- | ---- | ------------------------------------------------------------ | 925e41f4b71Sopenharmony_ci| index | number | 是 | 要滑动到的目标元素所在的ListItemGroup在当前容器中的索引值。 <br/>**说明:** <br/>index值设置成负值或者大于当前容器子组件的最大索引值,视为异常值,本次跳转不生效。 | 926e41f4b71Sopenharmony_ci| indexInGroup | number | 是 | 要滑动到的目标元素在index指定的ListItemGroup中的索引值。 <br/>**说明:** <br/>indexInGroup值设置成负值或者大于index指定的ListItemGroup容器子组件的最大索引值,视为异常值,本次跳转不生效。| 927e41f4b71Sopenharmony_ci| smooth | boolean | 否 | 设置滑动到列表项在列表中的索引值时是否有动效,true表示有动效,false表示没有动效。<br/>默认值:false。 | 928e41f4b71Sopenharmony_ci| align | [ScrollAlign](ts-container-scroll.md#scrollalign10枚举说明) | 否 | 指定滑动到的元素与当前容器的对齐方式。<br/>默认值:ScrollAlign.START。 | 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ci**错误码**: 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../../errorcode-universal.md)。 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 935e41f4b71Sopenharmony_ci| ------- | -------- | 936e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 937e41f4b71Sopenharmony_ci| 100004 | Controller not bound to component. | 938e41f4b71Sopenharmony_ci 939e41f4b71Sopenharmony_ci### closeAllSwipeActions<sup>11+</sup> 940e41f4b71Sopenharmony_ci 941e41f4b71Sopenharmony_cicloseAllSwipeActions(options?: [CloseSwipeActionOptions](#closeswipeactionoptions11对象说明)): void 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_ci将[EXPANDED](ts-container-listitem.md#swipeactionstate11枚举说明)状态的[ListItem](ts-container-listitem.md)收起,并设置回调事件。 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 948e41f4b71Sopenharmony_ci 949e41f4b71Sopenharmony_ci**参数:** 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 952e41f4b71Sopenharmony_ci| ------- | ------------------------------------ | ---- | ----------------------------------------------- | 953e41f4b71Sopenharmony_ci| options | [CloseSwipeActionOptions](#closeswipeactionoptions11对象说明) | 否 | 收起[EXPANDED](ts-container-listitem.md#swipeactionstate11枚举说明)状态的[ListItem](ts-container-listitem.md)的回调事件集合。 | 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ci**错误码**: 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../../errorcode-universal.md)。 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 961e41f4b71Sopenharmony_ci| ------- | -------- | 962e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 963e41f4b71Sopenharmony_ci| 100004 | Controller not bound to component. | 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ci> **说明:** 966e41f4b71Sopenharmony_ci> 967e41f4b71Sopenharmony_ci> - ListScroller必须绑定到List组件上。 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ci## OnScrollVisibleContentChangeCallback<sup>12+</sup> 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_citype OnScrollVisibleContentChangeCallback = (start: VisibleListContentInfo, end: VisibleListContentInfo) => void 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_ci有子组件划入或划出List显示区域时触发。 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 980e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------| 981e41f4b71Sopenharmony_ci| start | [VisibleListContentInfo](#visiblelistcontentinfo12对象说明) | 是 | 当前显示界面第一个ListItem或ListItemGroup的详细信息。 | 982e41f4b71Sopenharmony_ci| end | [VisibleListContentInfo](#visiblelistcontentinfo12对象说明) | 是 | 当前显示界面最后一个ListItem或ListItemGroup的详细信息。 | 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ci## VisibleListContentInfo<sup>12+</sup>对象说明 985e41f4b71Sopenharmony_ci 986e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 987e41f4b71Sopenharmony_ci 988e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 991e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------| 992e41f4b71Sopenharmony_ci| index | number | 是 | List显示区域内ListItem或ListItemGroup的索引值。 | 993e41f4b71Sopenharmony_ci| itemGroupArea | [ListItemGroupArea](#listitemgrouparea12枚举说明) | 否 | 如果当前可视页面的上边或下边在某个ListItemGroup之中,将会显示它所处的位置。 | 994e41f4b71Sopenharmony_ci| itemIndexInGroup | number | 否 | 如果当前可视页面的上边或下边在某个Group之中,将会显示Start或End的ListItem在Group中的索引。 | 995e41f4b71Sopenharmony_ci 996e41f4b71Sopenharmony_ci## ListItemGroupArea<sup>12+</sup>枚举说明 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 999e41f4b71Sopenharmony_ci 1000e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1003e41f4b71Sopenharmony_ci| ------ | ------ | ---------------------------------------- | 1004e41f4b71Sopenharmony_ci| NONE | 0 | 当前页面可视边处于none位置。例如,ListItemGroup中既没有header、footer,也没有ListItem。 | 1005e41f4b71Sopenharmony_ci| IN_LIST_ITEM_AREA | 1 | 当前页面可视边处于ListItem位置。 | 1006e41f4b71Sopenharmony_ci| IN_HEADER_AREA | 2 | 当前页面可视边处于header位置。 | 1007e41f4b71Sopenharmony_ci| IN_FOOTER_AREA | 3 | 当前页面可视边处于footer位置。 | 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_ci## 示例 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci### 示例1 1012e41f4b71Sopenharmony_ci该示例实现了设置纵向列表,并在当前显示界面发生改变时回调索引。 1013e41f4b71Sopenharmony_ci```ts 1014e41f4b71Sopenharmony_ci// xxx.ets 1015e41f4b71Sopenharmony_ci@Entry 1016e41f4b71Sopenharmony_ci@Component 1017e41f4b71Sopenharmony_cistruct ListExample { 1018e41f4b71Sopenharmony_ci private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 1019e41f4b71Sopenharmony_ci 1020e41f4b71Sopenharmony_ci build() { 1021e41f4b71Sopenharmony_ci Column() { 1022e41f4b71Sopenharmony_ci List({ space: 20, initialIndex: 0 }) { 1023e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number) => { 1024e41f4b71Sopenharmony_ci ListItem() { 1025e41f4b71Sopenharmony_ci Text('' + item) 1026e41f4b71Sopenharmony_ci .width('100%').height(100).fontSize(16) 1027e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF) 1028e41f4b71Sopenharmony_ci } 1029e41f4b71Sopenharmony_ci }, (item: string) => item) 1030e41f4b71Sopenharmony_ci } 1031e41f4b71Sopenharmony_ci .listDirection(Axis.Vertical) // 排列方向 1032e41f4b71Sopenharmony_ci .scrollBar(BarState.Off) 1033e41f4b71Sopenharmony_ci .friction(0.6) 1034e41f4b71Sopenharmony_ci .divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 1035e41f4b71Sopenharmony_ci .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring 1036e41f4b71Sopenharmony_ci .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { 1037e41f4b71Sopenharmony_ci console.info('first' + firstIndex) 1038e41f4b71Sopenharmony_ci console.info('last' + lastIndex) 1039e41f4b71Sopenharmony_ci console.info('center' + centerIndex) 1040e41f4b71Sopenharmony_ci }) 1041e41f4b71Sopenharmony_ci .onScrollVisibleContentChange((start: VisibleListContentInfo, end: VisibleListContentInfo) => { 1042e41f4b71Sopenharmony_ci console.log(' start index: ' + start.index + 1043e41f4b71Sopenharmony_ci ' start item group area: ' + start.itemGroupArea + 1044e41f4b71Sopenharmony_ci ' start index in group: ' + start.itemIndexInGroup) 1045e41f4b71Sopenharmony_ci console.log(' end index: ' + end.index + 1046e41f4b71Sopenharmony_ci ' end item group area: ' + end.itemGroupArea + 1047e41f4b71Sopenharmony_ci ' end index in group: ' + end.itemIndexInGroup) 1048e41f4b71Sopenharmony_ci }) 1049e41f4b71Sopenharmony_ci .onDidScroll((scrollOffset: number, scrollState: ScrollState) => { 1050e41f4b71Sopenharmony_ci console.info(`onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset) 1051e41f4b71Sopenharmony_ci }) 1052e41f4b71Sopenharmony_ci .width('90%') 1053e41f4b71Sopenharmony_ci } 1054e41f4b71Sopenharmony_ci .width('100%') 1055e41f4b71Sopenharmony_ci .height('100%') 1056e41f4b71Sopenharmony_ci .backgroundColor(0xDCDCDC) 1057e41f4b71Sopenharmony_ci .padding({ top: 5 }) 1058e41f4b71Sopenharmony_ci } 1059e41f4b71Sopenharmony_ci} 1060e41f4b71Sopenharmony_ci``` 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ci### 示例2 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_ci```ts 1068e41f4b71Sopenharmony_ci// xxx.ets 1069e41f4b71Sopenharmony_ci@Entry 1070e41f4b71Sopenharmony_ci@Component 1071e41f4b71Sopenharmony_cistruct ListLanesExample { 1072e41f4b71Sopenharmony_ci @State arr: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] 1073e41f4b71Sopenharmony_ci @State alignListItem: ListItemAlign = ListItemAlign.Start 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci build() { 1076e41f4b71Sopenharmony_ci Column() { 1077e41f4b71Sopenharmony_ci List({ space: 20, initialIndex: 0 }) { 1078e41f4b71Sopenharmony_ci ForEach(this.arr, (item: string) => { 1079e41f4b71Sopenharmony_ci ListItem() { 1080e41f4b71Sopenharmony_ci Text('' + item) 1081e41f4b71Sopenharmony_ci .width('100%') 1082e41f4b71Sopenharmony_ci .height(100) 1083e41f4b71Sopenharmony_ci .fontSize(16) 1084e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1085e41f4b71Sopenharmony_ci .borderRadius(10) 1086e41f4b71Sopenharmony_ci .backgroundColor(0xFFFFFF) 1087e41f4b71Sopenharmony_ci } 1088e41f4b71Sopenharmony_ci .border({ width: 2, color: Color.Green }) 1089e41f4b71Sopenharmony_ci }, (item: string) => item) 1090e41f4b71Sopenharmony_ci } 1091e41f4b71Sopenharmony_ci .height(300) 1092e41f4b71Sopenharmony_ci .width("90%") 1093e41f4b71Sopenharmony_ci .friction(0.6) 1094e41f4b71Sopenharmony_ci .border({ width: 3, color: Color.Red }) 1095e41f4b71Sopenharmony_ci .lanes({ minLength: 40, maxLength: 40 }) 1096e41f4b71Sopenharmony_ci .alignListItem(this.alignListItem) 1097e41f4b71Sopenharmony_ci .scrollBar(BarState.Off) 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_ci Button("点击更改alignListItem:" + this.alignListItem).onClick(() => { 1100e41f4b71Sopenharmony_ci if (this.alignListItem == ListItemAlign.Start) { 1101e41f4b71Sopenharmony_ci this.alignListItem = ListItemAlign.Center 1102e41f4b71Sopenharmony_ci } else if (this.alignListItem == ListItemAlign.Center) { 1103e41f4b71Sopenharmony_ci this.alignListItem = ListItemAlign.End 1104e41f4b71Sopenharmony_ci } else { 1105e41f4b71Sopenharmony_ci this.alignListItem = ListItemAlign.Start 1106e41f4b71Sopenharmony_ci } 1107e41f4b71Sopenharmony_ci }) 1108e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 }) 1109e41f4b71Sopenharmony_ci } 1110e41f4b71Sopenharmony_ci} 1111e41f4b71Sopenharmony_ci``` 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci 1116e41f4b71Sopenharmony_ci### 示例3 1117e41f4b71Sopenharmony_ci 1118e41f4b71Sopenharmony_ci```ts 1119e41f4b71Sopenharmony_ci// xxx.ets 1120e41f4b71Sopenharmony_ci@Entry 1121e41f4b71Sopenharmony_ci@Component 1122e41f4b71Sopenharmony_cistruct ListExample { 1123e41f4b71Sopenharmony_ci @State arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 1124e41f4b71Sopenharmony_ci @State editFlag: boolean = false 1125e41f4b71Sopenharmony_ci 1126e41f4b71Sopenharmony_ci build() { 1127e41f4b71Sopenharmony_ci Stack({ alignContent: Alignment.TopStart }) { 1128e41f4b71Sopenharmony_ci Column() { 1129e41f4b71Sopenharmony_ci List({ space: 20, initialIndex: 0 }) { 1130e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number, index?: number) => { 1131e41f4b71Sopenharmony_ci ListItem() { 1132e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { 1133e41f4b71Sopenharmony_ci Text('' + item) 1134e41f4b71Sopenharmony_ci .width('100%') 1135e41f4b71Sopenharmony_ci .height(80) 1136e41f4b71Sopenharmony_ci .fontSize(20) 1137e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1138e41f4b71Sopenharmony_ci .borderRadius(10) 1139e41f4b71Sopenharmony_ci .backgroundColor(0xFFFFFF) 1140e41f4b71Sopenharmony_ci .flexShrink(1) 1141e41f4b71Sopenharmony_ci if (this.editFlag) { 1142e41f4b71Sopenharmony_ci Button() { 1143e41f4b71Sopenharmony_ci Text("delete").fontSize(16) 1144e41f4b71Sopenharmony_ci }.width('30%').height(40) 1145e41f4b71Sopenharmony_ci .onClick(() => { 1146e41f4b71Sopenharmony_ci if (index != undefined) { 1147e41f4b71Sopenharmony_ci console.info(this.arr[index] + 'Delete') 1148e41f4b71Sopenharmony_ci this.arr.splice(index, 1) 1149e41f4b71Sopenharmony_ci console.info(JSON.stringify(this.arr)) 1150e41f4b71Sopenharmony_ci this.editFlag = false 1151e41f4b71Sopenharmony_ci } 1152e41f4b71Sopenharmony_ci }).stateEffect(true) 1153e41f4b71Sopenharmony_ci } 1154e41f4b71Sopenharmony_ci } 1155e41f4b71Sopenharmony_ci } 1156e41f4b71Sopenharmony_ci }, (item: string) => item) 1157e41f4b71Sopenharmony_ci }.width('90%') 1158e41f4b71Sopenharmony_ci .scrollBar(BarState.Off) 1159e41f4b71Sopenharmony_ci .friction(0.6) 1160e41f4b71Sopenharmony_ci }.width('100%') 1161e41f4b71Sopenharmony_ci 1162e41f4b71Sopenharmony_ci Button('edit list') 1163e41f4b71Sopenharmony_ci .onClick(() => { 1164e41f4b71Sopenharmony_ci this.editFlag = !this.editFlag 1165e41f4b71Sopenharmony_ci }).margin({ top: 5, left: 20 }) 1166e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 }) 1167e41f4b71Sopenharmony_ci } 1168e41f4b71Sopenharmony_ci} 1169e41f4b71Sopenharmony_ci``` 1170e41f4b71Sopenharmony_ci 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ci 1173e41f4b71Sopenharmony_ci### 示例4 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_ci```ts 1176e41f4b71Sopenharmony_ci// xxx.ets 1177e41f4b71Sopenharmony_ci@Entry 1178e41f4b71Sopenharmony_ci@Component 1179e41f4b71Sopenharmony_cistruct ListExample { 1180e41f4b71Sopenharmony_ci private arr: number[] = [] 1181e41f4b71Sopenharmony_ci private scrollerForList: Scroller = new Scroller() 1182e41f4b71Sopenharmony_ci 1183e41f4b71Sopenharmony_ci aboutToAppear() { 1184e41f4b71Sopenharmony_ci for (let i = 0; i < 20; i++) { 1185e41f4b71Sopenharmony_ci this.arr.push(i) 1186e41f4b71Sopenharmony_ci } 1187e41f4b71Sopenharmony_ci } 1188e41f4b71Sopenharmony_ci build() { 1189e41f4b71Sopenharmony_ci Column() { 1190e41f4b71Sopenharmony_ci Row() { 1191e41f4b71Sopenharmony_ci List({ space: 20, initialIndex: 3, scroller: this.scrollerForList }) { 1192e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number) => { 1193e41f4b71Sopenharmony_ci ListItem() { 1194e41f4b71Sopenharmony_ci Text('' + item) 1195e41f4b71Sopenharmony_ci .width('100%').height(100).fontSize(16) 1196e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1197e41f4b71Sopenharmony_ci } 1198e41f4b71Sopenharmony_ci .borderRadius(10).backgroundColor(0xFFFFFF) 1199e41f4b71Sopenharmony_ci .width('60%') 1200e41f4b71Sopenharmony_ci .height('80%') 1201e41f4b71Sopenharmony_ci }, (item: number) => JSON.stringify(item)) 1202e41f4b71Sopenharmony_ci } 1203e41f4b71Sopenharmony_ci .chainAnimation(true) 1204e41f4b71Sopenharmony_ci .edgeEffect(EdgeEffect.Spring) 1205e41f4b71Sopenharmony_ci .listDirection(Axis.Horizontal) 1206e41f4b71Sopenharmony_ci .height('100%') 1207e41f4b71Sopenharmony_ci .width('100%') 1208e41f4b71Sopenharmony_ci .scrollSnapAlign(ScrollSnapAlign.CENTER) 1209e41f4b71Sopenharmony_ci .borderRadius(10) 1210e41f4b71Sopenharmony_ci .backgroundColor(0xDCDCDC) 1211e41f4b71Sopenharmony_ci } 1212e41f4b71Sopenharmony_ci .width('100%') 1213e41f4b71Sopenharmony_ci .height('100%') 1214e41f4b71Sopenharmony_ci .backgroundColor(0xDCDCDC) 1215e41f4b71Sopenharmony_ci .padding({ top: 10 }) 1216e41f4b71Sopenharmony_ci } 1217e41f4b71Sopenharmony_ci } 1218e41f4b71Sopenharmony_ci} 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci``` 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_ci 1224e41f4b71Sopenharmony_ci### 示例5 1225e41f4b71Sopenharmony_ci该示例通过设置childrenMainSize属性,实现了List在子组件高度不一致时调用scrollTo接口也可以跳转准确。 1226e41f4b71Sopenharmony_ci```ts 1227e41f4b71Sopenharmony_ci// xxx.ets 1228e41f4b71Sopenharmony_ci@Entry 1229e41f4b71Sopenharmony_ci@Component 1230e41f4b71Sopenharmony_cistruct ListExample { 1231e41f4b71Sopenharmony_ci private arr: number[] = [] 1232e41f4b71Sopenharmony_ci private scroller: ListScroller = new ListScroller() 1233e41f4b71Sopenharmony_ci @State listSpace: number = 10 1234e41f4b71Sopenharmony_ci @State listChildrenSize: ChildrenMainSize = new ChildrenMainSize(100) 1235e41f4b71Sopenharmony_ci aboutToAppear(){ 1236e41f4b71Sopenharmony_ci // 初始化数据源。 1237e41f4b71Sopenharmony_ci for (let i = 0; i < 10; i++) { 1238e41f4b71Sopenharmony_ci this.arr.push(i) 1239e41f4b71Sopenharmony_ci } 1240e41f4b71Sopenharmony_ci // 前5个item的主轴大小不是默认大小100,因此需要通过ChildrenMainSize通知List。 1241e41f4b71Sopenharmony_ci this.listChildrenSize.splice(0, 5, [300, 300, 300, 300, 300]) 1242e41f4b71Sopenharmony_ci } 1243e41f4b71Sopenharmony_ci build() { 1244e41f4b71Sopenharmony_ci Column() { 1245e41f4b71Sopenharmony_ci List({ space: this.listSpace, initialIndex: 4, scroller: this.scroller }) { 1246e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number) => { 1247e41f4b71Sopenharmony_ci ListItem() { 1248e41f4b71Sopenharmony_ci Text('item-' + item) 1249e41f4b71Sopenharmony_ci .height( item < 5 ? 300 : this.listChildrenSize.childDefaultSize) 1250e41f4b71Sopenharmony_ci .width('90%') 1251e41f4b71Sopenharmony_ci .fontSize(16) 1252e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1253e41f4b71Sopenharmony_ci .borderRadius(10) 1254e41f4b71Sopenharmony_ci .backgroundColor(0xFFFFFF) 1255e41f4b71Sopenharmony_ci } 1256e41f4b71Sopenharmony_ci }, (item: string) => item) 1257e41f4b71Sopenharmony_ci } 1258e41f4b71Sopenharmony_ci .backgroundColor(Color.Gray) 1259e41f4b71Sopenharmony_ci .layoutWeight(1) 1260e41f4b71Sopenharmony_ci .scrollBar(BarState.On) 1261e41f4b71Sopenharmony_ci .childrenMainSize(this.listChildrenSize) 1262e41f4b71Sopenharmony_ci .alignListItem(ListItemAlign.Center) 1263e41f4b71Sopenharmony_ci Row(){ 1264e41f4b71Sopenharmony_ci Button() { Text('item size + 50') }.onClick(()=>{ 1265e41f4b71Sopenharmony_ci this.listChildrenSize.childDefaultSize += 50 1266e41f4b71Sopenharmony_ci }).height('50%').width('30%') 1267e41f4b71Sopenharmony_ci Button() { Text('item size - 50') }.onClick(()=>{ 1268e41f4b71Sopenharmony_ci if (this.listChildrenSize.childDefaultSize === 0) { 1269e41f4b71Sopenharmony_ci return 1270e41f4b71Sopenharmony_ci } 1271e41f4b71Sopenharmony_ci this.listChildrenSize.childDefaultSize -= 50 1272e41f4b71Sopenharmony_ci }).height('50%').width('30%') 1273e41f4b71Sopenharmony_ci Button() { Text('scrollTo (0, 310)') }.onClick(()=>{ 1274e41f4b71Sopenharmony_ci // 310: 跳转到item 1顶部与List顶部平齐的位置。 1275e41f4b71Sopenharmony_ci // 如果不设置childrenMainSize,item高度不一致时scrollTo会不准确。 1276e41f4b71Sopenharmony_ci this.scroller.scrollTo({xOffset: 0, yOffset: 310}) 1277e41f4b71Sopenharmony_ci }).height('50%').width('30%') 1278e41f4b71Sopenharmony_ci }.height('20%') 1279e41f4b71Sopenharmony_ci } 1280e41f4b71Sopenharmony_ci } 1281e41f4b71Sopenharmony_ci} 1282e41f4b71Sopenharmony_ci 1283e41f4b71Sopenharmony_ci``` 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci 1286e41f4b71Sopenharmony_ci 1287e41f4b71Sopenharmony_ci### 示例6 1288e41f4b71Sopenharmony_ci该示例展示了含有group时,获得List组件的Item索引相关信息。 1289e41f4b71Sopenharmony_ci```ts 1290e41f4b71Sopenharmony_ci// xxx.ets 1291e41f4b71Sopenharmony_ci@Entry 1292e41f4b71Sopenharmony_ci@Component 1293e41f4b71Sopenharmony_cistruct ListItemGroupExample { 1294e41f4b71Sopenharmony_ci private timeTable: TimeTable[] = [ 1295e41f4b71Sopenharmony_ci { 1296e41f4b71Sopenharmony_ci title: '星期一', 1297e41f4b71Sopenharmony_ci projects: ['语文', '数学', '英语'] 1298e41f4b71Sopenharmony_ci }, 1299e41f4b71Sopenharmony_ci { 1300e41f4b71Sopenharmony_ci title: '星期二', 1301e41f4b71Sopenharmony_ci projects: ['物理', '化学', '生物'] 1302e41f4b71Sopenharmony_ci }, 1303e41f4b71Sopenharmony_ci { 1304e41f4b71Sopenharmony_ci title: '星期三', 1305e41f4b71Sopenharmony_ci projects: ['历史', '地理', '政治'] 1306e41f4b71Sopenharmony_ci }, 1307e41f4b71Sopenharmony_ci { 1308e41f4b71Sopenharmony_ci title: '星期四', 1309e41f4b71Sopenharmony_ci projects: ['美术', '音乐', '体育'] 1310e41f4b71Sopenharmony_ci } 1311e41f4b71Sopenharmony_ci ] 1312e41f4b71Sopenharmony_ci private scroller: ListScroller = new ListScroller() 1313e41f4b71Sopenharmony_ci @State listIndexInfo: VisibleListContentInfo = {index: -1} 1314e41f4b71Sopenharmony_ci @State mess:string = "null" 1315e41f4b71Sopenharmony_ci @State itemBackgroundColorArr: boolean[] = [false] 1316e41f4b71Sopenharmony_ci @Builder 1317e41f4b71Sopenharmony_ci itemHead(text: string) { 1318e41f4b71Sopenharmony_ci Text(text) 1319e41f4b71Sopenharmony_ci .fontSize(20) 1320e41f4b71Sopenharmony_ci .backgroundColor(0xAABBCC) 1321e41f4b71Sopenharmony_ci .width("100%") 1322e41f4b71Sopenharmony_ci .padding(10) 1323e41f4b71Sopenharmony_ci } 1324e41f4b71Sopenharmony_ci 1325e41f4b71Sopenharmony_ci @Builder 1326e41f4b71Sopenharmony_ci itemFoot(num: number) { 1327e41f4b71Sopenharmony_ci Text('共' + num + "节课") 1328e41f4b71Sopenharmony_ci .fontSize(16) 1329e41f4b71Sopenharmony_ci .backgroundColor(0xAABBCC) 1330e41f4b71Sopenharmony_ci .width("100%") 1331e41f4b71Sopenharmony_ci .padding(5) 1332e41f4b71Sopenharmony_ci } 1333e41f4b71Sopenharmony_ci 1334e41f4b71Sopenharmony_ci build() { 1335e41f4b71Sopenharmony_ci Column() { 1336e41f4b71Sopenharmony_ci List({ space: 20, scroller: this.scroller}) { 1337e41f4b71Sopenharmony_ci ForEach(this.timeTable, (item: TimeTable, index: number) => { 1338e41f4b71Sopenharmony_ci ListItemGroup({ header: this.itemHead(item.title), footer: this.itemFoot(item.projects.length) }) { 1339e41f4b71Sopenharmony_ci ForEach(item.projects, (project: string, subIndex: number) => { 1340e41f4b71Sopenharmony_ci ListItem() { 1341e41f4b71Sopenharmony_ci Text(project) 1342e41f4b71Sopenharmony_ci .width("100%") 1343e41f4b71Sopenharmony_ci .height(100) 1344e41f4b71Sopenharmony_ci .fontSize(20) 1345e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1346e41f4b71Sopenharmony_ci .backgroundColor(this.itemBackgroundColorArr[index *3 +subIndex] ? 0x68B4FF: 0xFFFFFF) 1347e41f4b71Sopenharmony_ci } 1348e41f4b71Sopenharmony_ci }, (item: string) => item) 1349e41f4b71Sopenharmony_ci } 1350e41f4b71Sopenharmony_ci .divider({ strokeWidth: 1, color: Color.Blue }) // 每行之间的分界线 1351e41f4b71Sopenharmony_ci },(item: string) => item) 1352e41f4b71Sopenharmony_ci } 1353e41f4b71Sopenharmony_ci .width('90%') 1354e41f4b71Sopenharmony_ci .sticky(StickyStyle.Header | StickyStyle.Footer) 1355e41f4b71Sopenharmony_ci .scrollBar(BarState.Off) 1356e41f4b71Sopenharmony_ci .gesture( 1357e41f4b71Sopenharmony_ci PanGesture() 1358e41f4b71Sopenharmony_ci .onActionUpdate((event: GestureEvent) => { 1359e41f4b71Sopenharmony_ci if (event.fingerList[0] != undefined && event.fingerList[0].localX != undefined && event.fingerList[0].localY != undefined) { 1360e41f4b71Sopenharmony_ci this.listIndexInfo = this.scroller.getVisibleListContentInfo(event.fingerList[0].localX, event.fingerList[0].localY) 1361e41f4b71Sopenharmony_ci let itemIndex:string = 'undefined'; 1362e41f4b71Sopenharmony_ci if (this.listIndexInfo.itemIndexInGroup != undefined ) { 1363e41f4b71Sopenharmony_ci itemIndex = this.listIndexInfo.itemIndexInGroup.toString() 1364e41f4b71Sopenharmony_ci if (this.listIndexInfo.index != undefined && this.listIndexInfo.index >= 0 && 1365e41f4b71Sopenharmony_ci this.listIndexInfo.itemIndexInGroup >= 0 ) { 1366e41f4b71Sopenharmony_ci this.itemBackgroundColorArr[this.listIndexInfo.index * 3 + this.listIndexInfo.itemIndexInGroup] = true; 1367e41f4b71Sopenharmony_ci } 1368e41f4b71Sopenharmony_ci } 1369e41f4b71Sopenharmony_ci this.mess = 'index:' + this.listIndexInfo.index.toString() + ' itemIndex:' + itemIndex 1370e41f4b71Sopenharmony_ci } 1371e41f4b71Sopenharmony_ci })) 1372e41f4b71Sopenharmony_ci .gesture( 1373e41f4b71Sopenharmony_ci TapGesture({ count: 1 }) 1374e41f4b71Sopenharmony_ci .onAction((event: GestureEvent) => { 1375e41f4b71Sopenharmony_ci if (event) { 1376e41f4b71Sopenharmony_ci this.itemBackgroundColorArr.splice(0,this.itemBackgroundColorArr.length); 1377e41f4b71Sopenharmony_ci } 1378e41f4b71Sopenharmony_ci }) 1379e41f4b71Sopenharmony_ci ) 1380e41f4b71Sopenharmony_ci Text('您当前位置Item索引为'+ this.mess) 1381e41f4b71Sopenharmony_ci .fontColor(Color.Red) 1382e41f4b71Sopenharmony_ci .height(50) 1383e41f4b71Sopenharmony_ci }.width('100%').height('90%').backgroundColor(0xDCDCDC).padding({ top: 5 }) 1384e41f4b71Sopenharmony_ci } 1385e41f4b71Sopenharmony_ci} 1386e41f4b71Sopenharmony_ci 1387e41f4b71Sopenharmony_ciinterface TimeTable { 1388e41f4b71Sopenharmony_ci title: string; 1389e41f4b71Sopenharmony_ci projects: string[]; 1390e41f4b71Sopenharmony_ci} 1391e41f4b71Sopenharmony_ci 1392e41f4b71Sopenharmony_ci``` 1393e41f4b71Sopenharmony_ci 1394e41f4b71Sopenharmony_ci 1395e41f4b71Sopenharmony_ci 1396e41f4b71Sopenharmony_ci### 示例7 1397e41f4b71Sopenharmony_ci 1398e41f4b71Sopenharmony_ci```ts 1399e41f4b71Sopenharmony_ci// xxx.ets 1400e41f4b71Sopenharmony_ci//该示例实现了List组件开启边缘渐隐效果并设置边缘渐隐长度 1401e41f4b71Sopenharmony_ciimport { LengthMetrics } from '@kit.ArkUI' 1402e41f4b71Sopenharmony_ci@Entry 1403e41f4b71Sopenharmony_ci@Component 1404e41f4b71Sopenharmony_cistruct ListExample { 1405e41f4b71Sopenharmony_ci private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] 1406e41f4b71Sopenharmony_ci scrollerForList: Scroller = new Scroller() 1407e41f4b71Sopenharmony_ci build() { 1408e41f4b71Sopenharmony_ci Column() { 1409e41f4b71Sopenharmony_ci 1410e41f4b71Sopenharmony_ci List({ space: 20, initialIndex: 0, scroller: this.scrollerForList }) { 1411e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number) => { 1412e41f4b71Sopenharmony_ci ListItem() { 1413e41f4b71Sopenharmony_ci Text('' + item) 1414e41f4b71Sopenharmony_ci .width('100%').height(100).fontSize(16) 1415e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF) 1416e41f4b71Sopenharmony_ci } 1417e41f4b71Sopenharmony_ci }, (item: string) => item) 1418e41f4b71Sopenharmony_ci } 1419e41f4b71Sopenharmony_ci .fadingEdge(true,{fadingEdgeLength:LengthMetrics.vp(80)}) 1420e41f4b71Sopenharmony_ci } 1421e41f4b71Sopenharmony_ci .width('100%') 1422e41f4b71Sopenharmony_ci .height('100%') 1423e41f4b71Sopenharmony_ci .backgroundColor(0xDCDCDC) 1424e41f4b71Sopenharmony_ci .padding({ top: 5 }) 1425e41f4b71Sopenharmony_ci } 1426e41f4b71Sopenharmony_ci} 1427e41f4b71Sopenharmony_ci``` 1428e41f4b71Sopenharmony_ci 1429e41f4b71Sopenharmony_ci