新聞中心
想了解更多內(nèi)容,請(qǐng)?jiān)L問:

成都創(chuàng)新互聯(lián)自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元康平做網(wǎng)站,已為上家服務(wù),為康平各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220
和華為官方合作共建的鴻蒙技術(shù)社區(qū)
https://harmonyos./#zz
TableLayout簡(jiǎn)介
TableLayout意為表格布局,也可以稱為網(wǎng)格布局,允許我們使用表格的方式來排列組件,也就是行和列的方式。
TableLayout提供了用于在表格中對(duì)齊和排列組件的接口。可配置表格的排列方式,行數(shù)和列數(shù),以及組件的位置。
常用屬性
ohos:alignment_type表示設(shè)置網(wǎng)格布局中的對(duì)齊方式,默認(rèn)為align_contents(表示頁邊距對(duì)齊),還有一個(gè)參數(shù)是align_edges(表示邊界對(duì)齊)。
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:id="$+id:tableLayout"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:alignment_type="align_contents"
- ohos:background_element="#8AA7AA">
ohos:row_count表示設(shè)置網(wǎng)格布局中行數(shù),ohos:column_count表示設(shè)置網(wǎng)格布局中的列數(shù)。如果沒有為子組件設(shè)置值,則使用父組件默認(rèn)的行數(shù)和列數(shù)。在網(wǎng)格布局中若子組件的數(shù)量超出列數(shù)設(shè)置,則會(huì)自動(dòng)添加行數(shù)。比如下列代碼,我們?cè)O(shè)置一行,兩列,但是是三個(gè)子組件,我們監(jiān)聽其中一個(gè)按鈕的點(diǎn)擊事件,將行列數(shù)顯示在文本組件中。
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:id="$+id:tableLayout"
- ohos:height="match_content"
- ohos:width="match_content"
- ohos:row_count="1"
- ohos:column_count="2"
- ohos:background_element="#8AA7AA">
- ohos:id="$+id:tableTxt"
- ohos:height="match_content"
- ohos:width="match_content"
- ohos:text="我是文本組件"
- ohos:text_size="20fp"/>
- ohos:id="$+id:button"
- ohos:height="match_content"
- ohos:width="match_content"
- ohos:text="我是第一個(gè)按鈕"
- ohos:background_element="#5C6E71"
- ohos:text_color="#FFFFFF"
- ohos:text_size="20fp"/>
- ohos:id="$+id:btn"
- ohos:height="match_content"
- ohos:width="match_content"
- ohos:text="我是第二個(gè)按鈕"
- ohos:background_element="#5C6E71"
- ohos:text_color="#FFFFFF"
- ohos:text_size="20fp"/>
未觸發(fā)按鈕點(diǎn)擊事件的時(shí)候頁面顯示效果。
觸發(fā)按鈕點(diǎn)擊事件的時(shí)候頁面顯示效果。
ohos:orientation表示設(shè)置表格中組件的排列方式,水平(vertical)和垂直(horizontal)。如果我們?cè)O(shè)置行為1,列為2,子組件三個(gè),設(shè)置水平方向顯示,那么我們的列將失效,自動(dòng)會(huì)添加一列。
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:id="$+id:tableLayout"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:orientation="horizontal"
- ohos:background_element="#8AA7AA">
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:id="$+id:tableLayout"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:orientation="vertical"
- ohos:background_element="#8AA7AA">
示例
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:id="$+id:tableLayout"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:row_count="3"
- ohos:column_count="5"
- ohos:background_element="#8AA7AA">
- ohos:height="match_content"
- ohos:width="match_content"
- ohos:text="我是第1個(gè)按鈕"
- ohos:background_element="#07CCFF"
- ohos:text_color="#FFFFFF"
- ohos:text_size="20fp"
- ohos:padding="10vp"/>
- .....
想了解更多內(nèi)容,請(qǐng)?jiān)L問:
和華為官方合作共建的鴻蒙技術(shù)社區(qū)
https://harmonyos./#zz
分享標(biāo)題:鴻蒙HarmonyOSJavaUI之TableLayout布局示例
網(wǎng)頁地址:http://www.dlmjj.cn/article/dpopecs.html


咨詢
建站咨詢
