Android中的表格版面配置TableLayout,androidtablelayout

來源:互聯網
上載者:User

Android中的表格版面配置TableLayout,androidtablelayout

表格布局最主要的三個屬性:


XML代碼執行個體:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <!-- 定義第一個表格版面配置,指定第2列允許收縮,第3列允許展開 -->    <TableLayout android:id="@+id/TableLayout01"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:shrinkColumns="1"        android:stretchColumns="2"        >        <!-- 直接添加按鈕,它自己會佔一行 -->        <Button android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:id="@+id/ok1"            android:text="獨"            />        <!-- 添加一個表格行 -->        <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">            <Button android:id="@+id/ok2" android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普"/>            <Button android:id="@+id/ok3" android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="收"/>            <Button android:id="@+id/ok4" android:layout_width="wrap_content"                 android:layout_height="wrap_content" android:text="拉"/>        </TableRow>    </TableLayout>        <!-- 定義第二個表格版面配置,指定第2列隱藏 -->    <TableLayout android:id="@+id/TableLayout02" android:layout_marginTop="30dp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:collapseColumns="1"        >        <!-- 直接添加按鈕,它自己會佔一行 -->        <Button android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="獨"            />           <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普"/>            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="收"/>            <Button  android:layout_width="wrap_content"                 android:layout_height="wrap_content" android:text="拉"/>        </TableRow>    </TableLayout>        <!-- 定義第三個表格版面配置,指定第2列和第三列允許被展開 --><TableLayout android:id="@+id/TableLayout03"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:stretchColumns="1,2" android:layout_marginTop="30dp"    >      <Button android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="獨"     />      <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普通按鈕"/>            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="拉"/>            <Button  android:layout_width="wrap_content"                 android:layout_height="wrap_content" android:text="拉"/>       </TableRow>       <!-- 定義一個表格行 -->      <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">           <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普"/>            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="拉"/>      </TableRow></TableLayout></LinearLayout>

效果:


總結:

如果沒有用tableRow,直接用組件,將自己獨佔一行,並且填充父視窗

而如果用tableRow,上下兩行各列將對齊。


Android中TableLayout中的布局問題

使用weight屬性。將你控制項的layout中的width、height設定為fill-parent,
weight(權重)這個屬性很好的解決了這個問題。
 
android tablelayout布局填不滿螢幕怎辦???

樓主的tablelayout的高是怎麼設定的,是否用android:layout_height="fill_parent" ;
再者tablelayout是否嵌入在LinearLayout之中,如果的是話,LinearLayout的高是否也是android:layout_height="fill_parent" 。
只要tablelayout的高設定成填充滿父控制項,其父控制項也同樣如此設定tablelayout肯定能樸滿全屏目的。
那你的幾個TableRow的中有沒有用android:layout_weight="1",加入比重。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.