鸿蒙next版开发:ArkUI组件(GridRow/GridCol)

🚀一、GridRow/GridCol

🔎1.概述

栅格布局是一种通用的辅助定位工具,可以帮助开发人员解决多尺寸多设备的动态布局问题。通过将页面划分为等宽的列数和行数,栅格布局提供了可循的规律性结构,方便开发人员对页面元素进行定位和排版。此外,栅格布局还提供了一种统一的定位标注,帮助保证不同设备上各个模块的布局一致性,减少设计和开发的复杂度,提高工作效率。栅格布局还具有灵活的间距调整方法,可以满足特殊场景布局调整的需求。同时,自动换行和自适应功能使得栅格布局能够完成一对多布局,并自动适应不同设备上的排版。在栅格布局中,栅格容器组件GridRow与栅格子组件GridCol需要联合使用,共同构建出栅格布局场景。

🔎2.栅格容器GridRow

🦋2.1 栅格系统断点

断点名称 设备描述
xs 最小宽度类型设备
sm 小宽度类型设备
md 中等宽度类型设备
lg 大宽度类型设备
xl 特大宽度类型设备
xxl 超大宽度类型设备

在GridRow栅格组件中,开发者可以使用breakpoints自定义修改断点的取值范围,最多支持6个断点。除了默认的四个断点以外,还可以启用xl,xxl两个断点,支持六种不同尺寸(xs, sm, md, lg, xl, xxl)设备的布局设置。

定于如下:

breakpoints: {
  value: ['200vp', '300vp', '400vp', '500vp', '600vp'],
  reference: BreakpointsReference.WindowSize
}

案例如下:

@Entry
@Component
struct Index {
  @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown];
  build() {
    GridRow({
      breakpoints: {
        value: ['200vp', '300vp', '400vp', '500vp', '600vp'],
        reference: BreakpointsReference.WindowSize //断点切换参考物
      }
    }) {
      ForEach(this.bgColors, (color, index) => {
        GridCol({
          span: {
            xs: 2, // 在最小宽度类型设备上,栅格子组件占据的栅格容器2列。
            sm: 3, // 在小宽度类型设备上,栅格子组件占据的栅格容器3列。
            md: 4, // 在中等宽度类型设备上,栅格子组件占据的栅格容器4列。
            lg: 6, // 在大宽度类型设备上,栅格子组件占据的栅格容器6列。
            xl: 8, // 在特大宽度类型设备上,栅格子组件占据的栅格容器8列。
            xxl: 12 // 在超大宽度类型设备上,栅格子组件占据的栅格容器12列。
          }
        }) {
          Row() {
            Text(`${index}`)
          }.width("100%").height('50vp')
        }.backgroundColor(color)
      })
    }
  }
}

在这里插入图片描述

🦋2.2 布局的总列数

栅格布局的列数是指将页面宽度分为多少等分,一般情况下栅格布局的列数为12列,即将页面宽度分为12等分,每列所占宽度相等。这样可以方便地将页面元素放置到网格系统中,达到快速搭建页面的目的。同时,栅格布局的列数也可以根据具体的需求进行调整,并不一定非要是12列。

1、默认列数

columns默认值为12,即在未设置columns时,任何断点下,栅格布局被分成12列。

@Entry
@Component
struct Index {
  @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown];
  build() {
    GridRow() {
      ForEach(this.bgColors, (item, index) => {
        GridCol() {
          Row() {
            Text(`${index + 1}`)
          }.width('100%').height('50')
        }.backgroundColor(item)
      })
    }
  }
}         

<xsl:template match="w:tbl"> <xsl:variable name="colCount" select="count(w:tblGrid/w:gridCol)"/> <fo:table table-layout="fixed" width="100%" border-collapse="collapse"> <!-- 生成精确列定义 --> <xsl:for-each select="w:tblGrid/w:gridCol"> <fo:table-column column-width="{@w:w div 20}pt"/> </xsl:for-each> <fo:table-body> <!-- 列溢出检测逻辑保持不变 --> <xsl:if test="count(w:tr[1]/w:tc) > $colCount"> <fo:table-row> <fo:table-cell number-columns-spanned="{$colCount}"> <fo:block color="red">表格列数溢出警告</fo:block> </fo:table-cell> </fo:table-row> </xsl:if> <xsl:apply-templates select="w:tr"/> </fo:table-body> </fo:table> </xsl:template> <xsl:template match="w:tr"> <tr> <xsl:apply-templates select="w:tc"/> </tr> </xsl:template> <xsl:template match="w:tc"> <xsl:variable name="pos" select="count(preceding-sibling::w:tc) + 1"/> <xsl:variable name="vMergeStart" select="w:tcPr/w:vMerge/@w:val = 'restart' or (w:tcPr/w:vMerge and not(@w:val))"/> <xsl:variable name="rowspan"> <xsl:choose> <xsl:when test="$vMergeStart"> <xsl:call-template name="calculateRowspan"> <xsl:with-param name="currentRow" select="../following-sibling::w:tr"/> <xsl:with-param name="columnPos" select="$pos"/> <xsl:with-param name="count" select="1"/> </xsl:call-template> </xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:variable> <td> <xsl:if test="$rowspan > 1"> <xsl:attribute name="rowspan"> <xsl:value-of select="$rowspan"/> </xsl:attribute> </xsl:if> </td> </xsl:template> <xsl:template name="calculateRowspan"> <xsl:param name="currentRow"/> <xsl:param name="columnPos"/> <xsl:param name="count"/> <xsl:choose> <xsl:when test="$currentRow[1]/w:tc[position() = $columnPos]/w:tcPr/w:vMerge"> <xsl:call-template name="calculateRowspan"> <xsl:with-param name="currentRow" select="$currentRow[position() > 1]"/> <xsl:with-param name="columnPos" select="$columnPos"/> <xsl:with-param name="count" select="$count + 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$count"/> </xsl:otherwise> </xsl:choose> </xsl:template>我这个word的xml转xls-fo的xlst样式表,且xsl和xml本均为1.0,表格处理这块不能用,设计行或者列单元格合并有问题,请修改完善,一定要注意这是word的xml转xls-fo的xlst样式表,且xsl和xml本均为1.0,请直接给出修改结果
最新发布
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值