android布局之表单布局(TableLayout)

表单布局,要和TableLayout中的属性TableRow配合使用,我们要利用表单布局实现下图这样的一个布局,首先在这个布局中有一个表单的标题,这个表单有四列,下面分别对应相应的信息:



  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:stretchColumns="*"   
  6.     android:shrinkColumns="*">  
    1.     <!-- <pre name="code" class="html"><span style="white-space:pre">    </span>android:stretchColumns="*"将所有的列设置为伸展的,从而填充可利用的屏幕空间</pre><pre name="code" class="html"><span style="white-space:pre"></span><pre name="code" class="html"><span style="white-space:pre">  </span>android:shrinkColumns="*" 拉伸所有列,填满布局</pre><p></p>  
    2. <pre></pre>  
    3. -->    
    4. <pre></pre>  
    5. <pre name="code" class="html">     <TableRow  
    6.          android:id="@+id/tableRow4"  
    7.          android:layout_height="wrap_content"  
    8.          android:layout_width="match_parent">  
    9.         <TextView  
    10.              android:id="@+id/textView9"  
    11.              android:layout_width="match_parent"  
    12.              android:layout_height="wrap_content"  
    13.              android:textSize="18dp"  
    14.              android:text="Table 标题"  
    15.              android:gravity="center"  
    16.              android:layout_span="4"/>    
    17.      </TableRow>  
    18.     </pre><pre name="code" class="html"><span style="white-space:pre"</span><!-- <pre name="code" class="html"<span style="white-space:pre">    </span>android:gravity设置居中显示</pre><pre name="code" class="html"><pre name="code" class="html"><span style="white-space:pre">    </span>android:layout_span 跨四列</pre>  
    19. <pre></pre>  
    20. <span style="white-space:pre"></span>-->  
    21. <pre></pre>  
    22. <pre name="code" class="html">    <TableRow   
    23.           
    24.         >  
    25.         <TextView   
    26.             android:layout_width="wrap_content"  
    27.             android:layout_height="wrap_content"  
    28.             android:text="@string/name"  
    29.             />  
    30.           
    31.         <TextView   
    32.             android:layout_width="wrap_content"  
    33.             android:layout_height="wrap_content"  
    34.             android:text="@string/sex"  
    35.             />  
    36.           
    37.         <TextView   
    38.             android:layout_width="wrap_content"  
    39.             android:layout_height="wrap_content"  
    40.             android:text="@string/age"  
    41.             />  
    42.           
    43.         <TextView   
    44.             android:layout_width="wrap_content"  
    45.             android:layout_height="wrap_content"  
    46.             android:text="@string/phonenumber"  
    47.             />  
    48.           
    49.     </TableRow>  
    50.       
    51.     <TableRow >  
    52.         <TextView   
    53.             android:layout_width="wrap_content"  
    54.             android:layout_height="wrap_content"  
    55.             android:text="@string/nameZs"  
    56.             />  
    57.           
    58.         <TextView   
    59.             android:layout_width="wrap_content"  
    60.             android:layout_height="wrap_content"  
    61.             android:text="@string/sexZs"  
    62.             />  
    63.           
    64.         <TextView   
    65.             android:layout_width="wrap_content"  
    66.             android:layout_height="wrap_content"  
    67.             android:text="@string/ageZs"  
    68.             />  
    69.           
    70.         <TextView   
    71.             android:layout_width="wrap_content"  
    72.             android:layout_height="wrap_content"  
    73.             android:text="@string/phonenumberZs"  
    74.             />  
    75.           
    76.     </TableRow>  
    77.       
    78.     <TableRow >  
    79.         <TextView   
    80.             android:layout_width="wrap_content"  
    81.             android:layout_height="wrap_content"  
    82.             android:text="@string/nameLs"  
    83.             />  
    84.           
    85.         <TextView   
    86.             android:layout_width="wrap_content"  
    87.             android:layout_height="wrap_content"  
    88.             android:text="@string/sexLs"  
    89.             />  
    90.           
    91.         <TextView   
    92.             android:layout_width="wrap_content"  
    93.             android:layout_height="wrap_content"  
    94.             android:text="@string/ageLs"  
    95.             />  
    96.           
    97.         <TextView   
    98.             android:layout_width="wrap_content"  
    99.             android:layout_height="wrap_content"  
    100.             android:text="@string/phonenumberLs"  
    101.             />  
    102.           
    103.     </TableRow>  
    104.       
    105.   
    106. </TableLayout></pre><br>  
    107. 如有疑问清指出  
    108. <p></p>  
    109.      
    110. </pre></pre></pre
posted @ 2016-11-17 21:55  天涯海角路  阅读(195)  评论(0)    收藏  举报