zoukankan      html  css  js  c++  java
  • Android中的表格布局TableLayout

    表格布局最基本的三个属性:


    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,它自己会占一行 -->
            <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,它自己会占一行 -->
            <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"/>
                <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,上下两行各列将对齐。

  • 相关阅读:
    前端mvc mvp mvvm 架构介绍(vue重构项目一)
    SPA页面缓存再优化二
    消除浏览器对input输入框的自动填充
    单页面系统的一些性能优化
    城市联动组件插件思想分析
    前端性能优化点总结
    ui-router 1.0以上的 $stateChangeStart
    (转) view视图的放大、缩小、旋转
    (转)代码中实现button
    objective-c 强弱引用、properties的学习
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4352843.html
Copyright © 2011-2022 走看看