android學習筆記19--------------tablelayout的均分效果

來源:互聯網
上載者:User

TableLayout,表格版面配置採用行列形式管理UI組件,TableLayout不需要明確地聲明有多少行和列,而是通過添加TableRow、其它組件來控製表格的行數、列數。
每次向TableLayout添加一個TableRow,就是在向表格添加一行,TableRow也是容器,可以向TableRow中添加組件,每添加一個組件,即是添加一列。
如果直接向TableLayout添加組件,則認為這個組件佔用一行。
表格版面配置中列的寬度即是每一列中最寬的組件的寬度。
使用前:



使用後:



<TableLayout  
    android:id="@+id/tableLayout1"  
    android:layout_width="match_parent"  
    android:layout_height="wrap_content" 
    android:stretchColumns="*" > 
       <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"
     android:stretchColumns="*" >
        <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:stretchColumns="*" 表示所有列都要自動展開,以便適應螢幕寬度。

 

它的值即可以是數字,也可以是*,注意數字是從0開始的,即:android:stretchColumns="1" 是設定 TableLayout所有行的第二列為擴充列。

上面我們會看到 第1列的按鈕比其他列的按鈕要寬,如果我們想都一樣寬如何辦呢?

一個簡單辦法:

android:layout_width="1dip"


摘自 奔跑的蝸牛

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.