【问题标题】:How do I style HtmlView, such as center text?如何设置 HtmlView 的样式,例如居中文本?
【发布时间】:2018-12-05 17:59:31
【问题描述】:

我正在对通过 json 提要获得的一些 html 文本使用 HtmlView。但是,我想将它放在图像的中心,并且无法弄清楚如何在视图中设置元素的样式。我知道如何设置元素本身的宽度,但是如何设置内容的样式?

【问题讨论】:

    标签: nativescript


    【解决方案1】:

    text-align 与样式属性一起使用,

    <HtmlView html="<div style='text-align: center'>this text should be in center of view</div>"></HtmlView>
    

    注意:有人告诉我text-align: center 可能无法在 Android

    // Do this in loaded event of TextView
    const nativeView = args.object.android;
    if (nativeView) {
        nativeView.setGravity(android.view.Gravity.CENTER_HORIZONTAL);
    }
    

    Here 是 Playground 示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2015-04-01
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多