android布局文件詳解:android表格布局詳解

TableLayout(表格布局)

Android中的表格布局與HTML中的表格標籤< table >< tr >< td >相似,通過使用表格的行與列來排列組件。如果一行上有多個組件的話,就要在TableLayout中添加一個TableRow的容器,把組件都丟到裡面!一個Tablerow一行,有多少列則是看TableRow中的組件個數。

常用屬性

android:collapseColumns:隱藏某一列

android:shrinkColumns:允許某一列收縮

android:stretchColumns:拉伸某一列

這三個屬性的列號都是從0開始計算的,如shrinkColunmns = “3”,對應的是第四列,可以設置多個,用逗號隔開比如”0,3″,如果是所有列都生效,用”*”號即可。

android:layout_column=”3″:表示的就是跳過第三個,直接顯示到第四個格子處,從1開始計算。

android:layout_span=”2″:表示合併2個單元格,也就說這個組件佔2個單元格。

看代碼

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:stretchColumns="2"
    android:shrinkColumns="1">
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:id="@+id/button7"
            android:layout_width="139dp"
            android:layout_height="117dp"
            android:text="Button1" />

        <Button
            android:id="@+id/button6"
            android:layout_width="139dp"
            android:layout_height="117dp"
            android:text="Button2" />

        <Button
            android:id="@+id/button4"
            android:layout_width="139dp"
            android:layout_height="117dp"
            android:text="Button3" />
    </TableRow>
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:id="@+id/button9"
            android:layout_width="139dp"
            android:layout_height="117dp"
            android:text="Button4" />
        <Button
            android:id="@+id/button8"
            android:layout_width="139dp"
            android:layout_height="117dp"
            android:text="Button5" />
        <Button
            android:id="@+id/button5"
            android:layout_width="139dp"
            android:layout_height="117dp"
            android:text="Button6" />
    </TableRow>
</TableLayout>

效果圖

安卓界面布局之表格布局與幀布局

FrameLayout(幀布局)

幀布局是最為簡單的一種布局,該布局為每個加入其中的控制項創建一個空白區域,稱為一幀,每個控制項佔據一幀。採用幀布局時,所有控制項都默認顯示在屏幕左上角,並按照先後放入的順序重疊擺放,先放入的將會在最底層,後放入的控制項顯示在最頂層。幀布局使用於圖層設計。

屬性

foreground :設置幀布局容器的前景圖像

foregroundGravity :屬性設置圖像的顯示位置

看代碼

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="@mipmap/ic_launcher"
    android:foregroundGravity="bottom">
    <TextView
        android:id="@+id/textView"
        android:layout_width="460dp"
        android:layout_height="336dp"
        android:background="@color/colorAccent"
        android:text="TextView" />
    <TextView
        android:id="@+id/textView2"
        android:layout_width="332dp"
        android:layout_height="242dp"
        android:background="@color/colorPrimary"
        android:text="TextView" />
</FrameLayout>

效果圖

安卓界面布局之表格布局與幀布局

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/222906.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-09 14:13
下一篇 2024-12-09 14:13

相關推薦

發表回復

登錄後才能評論