其他分享
首页 > 其他分享> > harmonyOS应用-TableLayout布局

harmonyOS应用-TableLayout布局

作者:互联网

TableLayout布局

harmonyOS官网网址:https://developer.harmonyos.com

TableLayout使用表格的方式划分子组件,如下图示例
在这里插入图片描述
在XML文件中创建TableLayout以及添加组件

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:background_element="$graphic:color_cyan_element"
    ohos:layout_alignment="horizontal_center"
    ohos:padding="8vp">

    <Text
        ohos:id="$+id:table_text_1"
        ohos:width="100vp"
        ohos:height="50vp"
        ohos:background_element="$graphic:color_red_element"
        ohos:margin="10vp"
        ohos:text_alignment="horizontal_center"
        ohos:text_size="30fp"
        ohos:text="text_1"
        />
    <Text
        ohos:id="$+id:table_text_2"
        ohos:width="100vp"
        ohos:height="50vp"
        ohos:background_element="$graphic:color_red_element"
        ohos:margin="10vp"
        ohos:text_alignment="horizontal_center"
        ohos:text_size="30fp"
        ohos:text="text_2"
        />

    <Text
        ohos:id="$+id:table_text_3"
        ohos:width="100vp"
        ohos:height="50vp"
        ohos:background_element="$graphic:color_red_element"
        ohos:margin="10vp"
        ohos:text_alignment="horizontal_center"
        ohos:text_size="30fp"
        ohos:text="text_3"
        />
    <Text
        ohos:id="$+id:table_text_4"
        ohos:width="100vp"
        ohos:height="50vp"
        ohos:background_element="$graphic:color_red_element"
        ohos:margin="10vp"
        ohos:text_alignment="horizontal_center"
        ohos:text_size="30fp"
        ohos:text="text_4"
        />
    <Text
        ohos:id="$+id:table_text_5"
        ohos:width="100vp"
        ohos:height="50vp"
        ohos:background_element="$graphic:color_red_element"
        ohos:margin="10vp"
        ohos:text_alignment="horizontal_center"
        ohos:text_size="30fp"
        ohos:text="text_5"
        />
</TableLayout>

默认的排列方式–垂直排列
在这里插入图片描述
设置行数和列数


      <TableLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:background_element="$graphic:color_cyan_element"
    ohos:layout_alignment="horizontal_center"
    ohos:padding="8vp"
    ohos:row_count="2"
    ohos:column_count="2">
    </TableLayout>

在这里插入图片描述
设置对齐方式alignment_type属性表设置好像没有效果-----还不清楚除原有

属性值效果
align_edges表示子组件边界对齐,默认对齐方式。
align_contents表示子组件边距对齐

在XML中设置对齐方式,以”align_contents“为例:ohos:alignment_type="align_contents

标签:align,布局,harmonyOS,TableLayout,设置,组件,对齐,contents
来源: https://blog.csdn.net/qq_20852367/article/details/111893114