HarmonyOS RichEditor组件内容超出当前默认范围时,会占用其他的组件的位置。如何让其自动进行滚动,而不影响其他组件的显示

RichEditor组件在内容超过显示界面时,不会自动滚动,会把下方的控件覆盖。

代码如下:

import promptAction from '@ohos.promptAction';
import router from '@ohos.router'; // 引入router

@Entry
@Component
struct Index {
  // private defaultTextStyle : boolean = false;
  controller: RichEditorController = new RichEditorController();
  options: RichEditorOptions = { controller: this.controller };

  newContext() {
    this.controller.addTextSpan("0123456789\n", {
      style: {
        fontColor: Color.Pink,
        fontSize: "32",
      },
      paragraphStyle: {
        textAlign: TextAlign.Start,
        leadingMargin: 16
      }
    })
    this.controller.addTextSpan("012345678901234567890123456789012345678901234567890123456789\n", {
      style: {},
      paragraphStyle: {
        textAlign: TextAlign.Start,
        leadingMargin: 16
      }
    })
  }

  build() {
    Column() {
      //标题栏
      Row() {
        Column() {
          Button() {
            Image($r('app.media.icon_back'))
              .width($r('app.float.icon_size'))
              .height($r('app.float.icon_size'))
          }
          .width($r('app.float.hgt_item'))
          .height($r('app.float.hgt_item'))
          .stateStyles({
            normal: { .backgroundColor($r('app.color.clr_major'))
            },
            pressed: { .backgroundColor($r('app.color.clr_button_bg'))
            },
          })
          .onClick(() => {
            router.back();
          })
        }
        .justifyContent(FlexAlign.Center)
        .width($r('app.float.hgt_item'))
        .height($r('app.float.hgt_caption'))

        Column() {
          Text('用户输入')
            .width('100%')
            .height($r('app.float.hgt_caption'))
            .fontSize($r('app.integer.font_caption'))
            .fontColor($r('app.color.start_main'))
            .fontWeight(FontWeight.Normal)
            .textAlign(TextAlign.Center)
        }
        .justifyContent(FlexAlign.Center)
        .flexShrink(1)

        Column()
          .justifyContent(FlexAlign.Center)
          .width($r('app.float.hgt_item'))
          .height($r('app.float.hgt_caption'))
      }
      .width('100%')
      .height($r('app.float.hgt_caption'))
      .backgroundColor($r('app.color.clr_major'))

      RichEditor(this.options)
        .width('100%')
        .clip(true)
        .flexGrow(1)
        .expandSafeArea([SafeAreaType.KEYBOARD])
        .onReady(() => {
          this.newContext()
        })
      Divider().strokeWidth(10).color($r('app.color.clr_background'))
      Button('复制内容')
        .width('80%')
        .height($r('app.float.hgt_item'))
        .onClick(() => {
          this.newContext()
        }) //Button
    }
    .height('100%')
    .width('100%')
    .backgroundColor($r('app.color.clr_background'))
  }
}
HarmonyOS
2025-01-09 17:28:39
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

可将RichEditor放入滑动组件中:

Scroll() {
  RichEditor()
    .width('100%')
    .height('300vp') // 设置合适的高度,根据实际需求调整  
}
分享
微博
QQ
微信
回复
2025-01-09 19:22:55
相关问题
如何在Tabs中tabBar,添加其他组件
1071浏览 • 1回复 待解决
如何设置组件尺寸范围
660浏览 • 1回复 待解决
HarmonyOS组件超过父组件范围
392浏览 • 1回复 待解决
HarmonyOS Text组件获取当前显示行数
294浏览 • 1回复 待解决
HarmonyOS使用Web组件如何监听滚动位置
873浏览 • 2回复 待解决