HarmonyOS List上展示html字符串

1、RichText展示html时,字体大小很小。例如:

<span style='font-size: 18px;'><a><span style='color: #16abf0;'>测试</span></a>服务</span>
  • 1.

使用RichText展示时,字体很小。

2、官方文档上关于List上使用RichText场景:

RichText组件比较消耗内存资源,而且有一些重复使用RichText组件的场景下,比如在List下循环重复使用RichText时,会出现卡顿、滑动响应慢等现象。在这种情况下,推荐使用RichEditor组件。`

请问有List上使用RichEditor解析html的实例吗? 例如List上使用RichEditor解析。

HarmonyOS
2024-09-03 09:16:48
919浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

参考demo如下:

class ArrayList { 
  text: string 
  color: ResourceStr 
  public clickEvent: () => void = () => { 
  } 
 
  constructor(text: string, color: ResourceStr) { 
    this.text = text 
    this.color = color 
  } 
  public onClick(event: () => void): ArrayList { 
    this.clickEvent = event 
    return this 
  } 
} 
@Entry 
@Component 
struct Index { 
  controller: RichEditorController = new RichEditorController(); 
  options: RichEditorOptions = { controller: this.controller }; 
  @State arrayList: Array<ArrayList> = [ 
    new ArrayList(",", "#16abf0").onClick(() => { 
      console.log("") 
    }), 
    new ArrayList("test", "#16abf0").onClick(() => { 
      console.log("test") 
    }), 
    new ArrayList("demo示例", "#ffc6131f").onClick(() => { 
      console.log("demo示例") 
    }), 
    new ArrayList("是否满足", "#16abf0").onClick(() => { 
      console.log("是否满足") 
    }) 
  ] 
  @Builder 
  my_builder(item: string) { 
    Column() { 
      Text(item) 
    } 
  } 
  build() { 
    Column() { 
      List() { 
        ForEach(this.arrayList, (item: ArrayList) => { 
          ListItem() { 
            Column() { 
              RichEditor(this.options) 
                .onReady(() => { 
                  this.controller.addTextSpan(item.text, 
                    { 
                      style: 
                      { 
                        fontColor: item.color, 
                        fontSize: 18, 
                      }, 
                      gesture: { 
                        onClick: () => { 
                          if (item.clickEvent) { 
                            item.clickEvent() 
                          } 
                        } 
                      } 
                    }) 
                }) 
            } 
          } 
        }) 
      } 
    } 
    .width("100%") 
    .height('100%') 
    .backgroundColor($r('sys.color.ohos_id_color_sub_background')) 
  } 
}
  • 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.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
分享
微博
QQ
微信
回复
2024-09-03 15:12:54


相关问题
List展示服务端下发的HTML字符串
737浏览 • 1回复 待解决
HarmonyOS 如何支持html格式字符串
653浏览 • 1回复 待解决
HarmonyOS Web组件如何加载html字符串
1730浏览 • 1回复 待解决
HarmonyOS web组件怎么加载html字符串
662浏览 • 1回复 待解决
Web如何使用loadData加载复杂Html字符串
3252浏览 • 1回复 待解决
检查字符串是否以给定的字符串开头
1481浏览 • 1回复 待解决
字符串反射
725浏览 • 1回复 待解决
HarmonyOS 替换字符串
1064浏览 • 1回复 待解决
HarmonyOS 字符串显示异常
1148浏览 • 1回复 待解决
HarmonyOS字符串替换问题
1778浏览 • 1回复 待解决
检查字符串是否以给定的字符串结尾
1254浏览 • 1回复 待解决
HarmonyOS 字符串编码问题
726浏览 • 1回复 待解决
HarmonyOS ASCII转字符串
839浏览 • 1回复 待解决
HarmonyOS 字符串转图片
888浏览 • 1回复 待解决
HarmonyOS 替换字符串问题
1162浏览 • 1回复 待解决
HarmonyOS string字符串截取问题
968浏览 • 1回复 待解决