HarmonyOS Component叠加到Scroll上,怎么设置margin和宽高

Component叠加到Scroll上,怎么设置margin和宽高

HarmonyOS
2024-12-20 16:49:14
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

参考demo:

@Entry
@Component
struct NestedScroll {
  @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。
  private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  private scrollerForScroll: Scroller = new Scroller()
  private scrollerForList: Scroller = new Scroller()

  build() {
    Flex() {
      Scroll(this.scrollerForScroll) {
        Column() {
          List({ space: 20, scroller: this.scrollerForList }) {
            ForEach(this.arr, (item: number) => {
              ListItem() {
                Text("ListItem" + item)
                  .width("100%")
                  .height("100%")
                  .borderRadius(15)
                  .fontSize(16)
                  .textAlign(TextAlign.Center)
                  .backgroundColor(Color.White)
              }.width("100%").height(100)
            }, (item: string) => item)
          }
          .width("100%")
          .height("50%")
          .edgeEffect(EdgeEffect.None)
          .friction(0.6)
          .onReachStart(() => {
            this.listPosition = 0
          })
          .onReachEnd(() => {
            this.listPosition = 2
          })
          .onScrollFrameBegin((offset: number) => {
            if ((this.listPosition == 0 && offset <= 0) || (this.listPosition == 2 && offset >= 0)) {
              this.scrollerForScroll.scrollBy(0, offset)
              return { offsetRemain: 0 }
            }
            this.listPosition = 1
            return { offsetRemain: offset };
          })
          AreaTest()
        }
      }
      .width("100%").height("100%")
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20)
  }
}


@Component struct AreaTest {
  build() {
    Text("Scroll Area")
      .width("100%")
      .height("40%")
      .backgroundColor(0X330000FF)
      .fontSize(16)
      .textAlign(TextAlign.Center)
      .margin(90)
  }
}
分享
微博
QQ
微信
回复
2024-12-20 19:07:38
相关问题
HarmonyOS中的window怎么设置固定
1972浏览 • 1回复 待解决
HarmonyOS RelativeContainer设置问题
224浏览 • 1回复 待解决
HarmonyOS ArkUI中设置
331浏览 • 1回复 待解决
图片压缩指定限制大小
1323浏览 • 1回复 待解决
如何获取组件和在屏幕的位置
3710浏览 • 2回复 待解决
HarmonyOS 怎么在Page中获取窗口的
275浏览 • 1回复 待解决
HarmonyOS 怎么获取网络图的实际
307浏览 • 1回复 待解决
HarmonyOS richtext如何控制
294浏览 • 1回复 待解决