@Entry
@Component
struct LongTextSolution1 {
textContent: string =
"这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。" +
"这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。";
build() {
Column() {
Scroll() {
Column() {
Text(this.textContent)
.fontSize(16);
}
.width('100%');
}
.width('90%')
.height(100)
.padding(10)
.borderRadius(12)
.scrollBar(BarState.Off)
.backgroundColor('#f1f3f5');
}
.width('100%')
.alignItems(HorizontalAlign.Center)
.margin({ top: 16 });
}
} 效果图如下:

@Entry
@Component
struct LongTextSolution2 {
textContent: string =
"这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。" +
"这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。";
build() {
Column() {
Column() {
Text(this.textContent)
.fontSize(16)
.maxLines(4)
.width('100%')
.textOverflow({ overflow: TextOverflow.Ellipsis })
.bindContextMenu(this.buildContextMenu, ResponseType.LongPress, { backgroundColor: Color.White });
}
.width('90%')
.height(100)
.padding(10)
.borderRadius(12)
.backgroundColor('#f1f3f5');
}
.width('100%')
.alignItems(HorizontalAlign.Center)
.margin({ top: 16 });
}
@Builder
buildContextMenu() {
Text(this.textContent)
.fontSize(16)
.margin(24);
}
} 效果图如下:

@Entry
@Component
struct LongTextSolution3 {
textContent: string =
"这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。" +
"这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。这是一段测试文本。";
build() {
Column() {
Column() {
Text(this.textContent)
.fontSize(16)
.height('auto');
}
.width('90%')
.height('auto')
.padding(10)
.borderRadius(12)
.backgroundColor('#f1f3f5');
}
.width('100%')
.alignItems(HorizontalAlign.Center)
.margin({ top: 16 });
}
} 效果图如下:
