[Android Studio 30天自我挑战] TableLayout元件对齐方式

TableLayout为表格布局,顾名思义就是利用表格方式来布局
TableLayout里面是透过TableRow来区别每一列,但TableLayout会以最多栏数那列来统一让所有列数都有相同的的栏数。
若想要让某一格跨越栏数可以使用android:layout_span来修改,这样就不会每一列被固定格数。

常用属性

android:layout_colum:为设定该元件在TableRow中指定的列
android:layout_span:为设定该元件所跨越的列数
android:collapseColumns:可设定TableLayout里指定的列隐藏,若要隐藏多行时需用「,」隔开,起始值为0。
** android:stretchColumns**:设置指定的列为可延伸的,填满剩下的多余的空间,填满多行需用「,」隔开,起始值为0。
android:shrinkColumns:设置指定的列为可收缩的列,多行时需用「,」隔开,起始值为0。

范例:

    <TableRow>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Button1"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button2"/>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Button3"/>
    </TableRow>

    <TableRow>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="这个是  Button  4"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button5"
            android:layout_span="1"/> //Button5只对齐Button2
    </TableRow>

Button4的长度比较长所以Button1的长度就会跟着变长
而android:layout_span="1"的意思就是Button5只跨越1个的栏数所以会刚好对齐Button2
结果为:
https://ithelp.ithome.com.tw/upload/images/20210906/20139258OpokBmMQup.png

若android:layout_span="2"时,Button5则会对齐到Button3
结果为:

https://ithelp.ithome.com.tw/upload/images/20210906/20139258CuxagS6jZs.png


<<:  Day 4 初始化的 RSpec 资料夹剖析

>>:  未知的第四天 -新增页面

Day 10. 新手也能懂的物件导向 part 2

上一篇讲了一部分物件导向的特性,今天要来讲多型,在此之前要先介绍介面(interface),以及他的...

Day13 Android - banner(横幅广告)应用(2)

接下来要讲有关线上取图的banner,会分开主要是因为有些微的不一样,包含在Manifest中添加网...

Rust-定义函式Function(三)

提前退出 正常情况是必须达到函示的末尾,但是如果编写包含许多语法的函式通常会在意识到没有更多计算要做...

[Day 23] 实作-搜寻表单 v-expansion-panels

昨天设计完介面了, 今天就是做前端啦,建立新页面跟放上面的header照片,之前都讲过了 Expan...

[Day3] 人脸侦测 (Face Detection)

小游戏,威利在哪里? (威利穿着红白条纹的衬衫并戴着一个绒球帽,手上拿着木制的手杖,还戴着一副眼镜...