是否有API能够返回当前ListItemGroup的Header吸顶的状态?
原理说明:
- @Entry
- @Component
- struct StickyHeaderExample {
- private arr: number[] = [0, 1];
-
- @Builder
- CustomHeader() {
- Text('分组标题')
- .height(50)
- .width('100%')
- .backgroundColor(Color.Gray)
- .onAreaChange((oldValue: Area, newValue: Area) => {
- if (oldValue.position.y === 0 && newValue.position.y === 0) {
- console.info('没吸顶');
- } else {
- console.info(`吸顶了 ${oldValue.position.y}`);
- }
- });
- }
-
- build() {
- Column() {
- List({ space: 10 }) {
- ForEach(this.arr, (item: number) => {
- ListItem() {
- Text(item.toString())
- .width('100%')
- .height(50)
- .fontSize(16)
- .textAlign(TextAlign.Center)
- .borderRadius(10)
- .backgroundColor(0xFFFFFF);
- };
- }, (item: string) => item);
- ListItemGroup({
- header: this.CustomHeader,
- space: 10
- }) {
- ForEach(Array.from({ length: 20 }), (item: void, index: number) => {
- ListItem() {
- Text(`列表项 ${index}`)
- .height(80)
- .width('100%')
- .backgroundColor('#FFF');
- };
- });
- };
- }
- .sticky(StickyStyle.Header)
- .width('100%')
- .height('100%');
- };
- }
- }
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功