灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2009回复:0

android学习笔记19---------tablelayout的均分效果

楼主#
更多 发布于:2012-09-06 13:43

TableLayout,表格布局采用行列形式管理UI组件,TableLayout不需要明确地声明有多少行和列,而是通过添加TableRow、其它组件来控制表格的行数、列数。
每次向TableLayout添加一个TableRow,就是在向表格添加一行,TableRow也是容器,可以向TableRow中添加组件,每添加一个组件,即是添加一列。
如果直接向TableLayout添加组件,则认为这个组件占用一行。
表格布局中列的宽度即是每一列中最宽的组件的宽度。
使用前:




使用后:





<TableLayout  
    Android:id="@+id/tableLayout1"  
    Android:layout_width="match_parent"  
    Android:layout_height="wrap_content"
    AndroidtretchColumns="*" >
       <TableRow  
        Android:id="@+id/tableRow1"  
        Android:layout_width="wrap_content"  
        Android:layout_height="wrap_content">        
           <Button  
            Android:text="最近联系人"  
            Android:id="@+id/button4"  
            Android:layout_width="1dip"  
            Android:layout_height="wrap_content"></Button>    
            
             <Button  
                Android:text="联系人"  
                Android:id="@+id/button5"  
                Android:layout_width="1dip"  
                Android:layout_height="wrap_content"></Button>  
                
             <Button  
                Android:text="分组"  
                Android:id="@+id/button5"  
                Android:layout_width="1dip"  
                Android:layout_height="wrap_content"></Button>  
                      
           </TableRow>
      
    
   </TableLayout>
<TableLayout
     Android:id="@+id/tableLayout1"
     Android:layout_width="match_parent"
     Android:layout_height="wrap_content"
     AndroidtretchColumns="*" >
        <TableRow
         Android:id="@+id/tableRow1"
         Android:layout_width="wrap_content"
         Android:layout_height="wrap_content">      
            <Button
             Android:text="最近联系人"
             Android:id="@+id/button4"
             Android:layout_width="1dip"
             Android:layout_height="wrap_content"></Button>  
            
             <Button
                Android:text="联系人"
                Android:id="@+id/button5"
                Android:layout_width="1dip"
                Android:layout_height="wrap_content"></Button>
                
              <Button
                Android:text="分组"
                Android:id="@+id/button5"
                Android:layout_width="1dip"
                Android:layout_height="wrap_content"></Button>
                    
            </TableRow>
      
    
    </TableLayout>
TableLayout 增加一个属性 AndroidtretchColumns="*" 表示所有列都要自动拉伸,以便适应屏幕宽度。

它的值即可以是数字,也可以是*,注意数字是从0开始的,即:AndroidtretchColumns="1" 是设置 TableLayout所有行的第二列为扩展列。
上面我们会看到 第1列的按钮比其他列的按钮要宽,如果我们想都一样宽如何办呢?
一个简单办法:
Android:layout_width="1dip"


喜欢0 评分0
游客

返回顶部