#鸿蒙通关秘籍#如何使用NavDestination和Scroll创建知乎日报详情页面?

HarmonyOS
2024-11-28 16:20:09
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
hm673ff0ed6638a

使用NavDestination容纳整个页面布局,并结合Scroll组件来允许用户滚动浏览详情页面内容。以下是实现代码:

NavDestination() {
  Scroll() {
    Column({ space: 0 }) {
      Stack({ alignContent: Alignment.Bottom }) {
        Image(this.detailData?.image).width('100%').height(250).zIndex(1);

        Text(this.detailData?.title)
          .padding(5)
          .margin({ bottom: 10 })
          .width('100%')
          .height(50)
          .textAlign(TextAlign.Center)
          .maxLines(2)
          .textOverflow({ overflow: TextOverflow.Clip })
          .fontSize(16)
          .fontColor(Color.White)
          .opacity(100)
          .backgroundColor('#808080AA')
          .zIndex(2);
      }.height(250);

      Text(`${this.detailData?.author ?? ""} ${this.detailData?.bio ?? ""}`)
        .fontSize(14)
        .fontColor("#999")
        .padding(10).width('100%');

      Column() {
        ForEach(this.detailData?.content, (item: ZhiDetailItem, idx) => {
          if (item.types === 'p') {
            Text(item.value).fontSize(16).padding(10).lineSpacing(LengthMetrics.px(30)).width('100%').alignSelf(ItemAlign.Start);
          } else if (item.types === 'p.strong') {
            Text(item.value).fontSize(16).fontWeight(FontWeight.Bold).padding(10).width('100%').alignSelf(ItemAlign.Start);
          } else if (item.types === 'img') {
            Image(item.value).padding(10);
          }
        });
      }
    }
  }
}
.title("日报详情")
.width('100%')
.height('100%')
  • 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.
分享
微博
QQ
微信
回复
2024-11-28 16:00:34


相关问题
鸿蒙系统-如何跳转应用信息详情页面
10840浏览 • 2回复 待解决
HarmonyOS 应用市场详情页面地址
706浏览 • 1回复 待解决
商品详情页面的常规布局方式
1197浏览 • 1回复 待解决
如何跳转到设置中的应用详情页面
3079浏览 • 1回复 待解决
如何跳转设置—应用详情页
2664浏览 • 1回复 待解决