首页 > 移动平台 > 详细

UI篇--Android中TableLayout中的布局

时间:2014-02-19 09:21:19      阅读:597      评论:0      收藏:0      [点我收藏+]

1.TableLayout下的代码及效果

bubuko.com,布布扣
<TableRow>  
        <TextView android:text="tmacsky" />  
        <TextView android:text="tmacsky" />  
        <TextView android:text="tmacsky" />  
    </TableRow>  
    <TableRow>  
        <Button android:text="tmacsky" />  
        <Button android:text="tmacsky" />  
        <Button android:text="tmacsky" android:layout_weight="1" />  
    </TableRow>  
    <TableRow>  
        <EditText />  
        <EditText />  
        <EditText android:layout_weight="1"/>  
</TableRow>
bubuko.com,布布扣


bubuko.com,布布扣

单个列布局中只能用layout_weight来拉宽,如果布局很多就有点繁琐了,所以得用到下面的stretchColumns伸缩列

2. Android:stretchColumns 伸缩列 

代码和效果:

bubuko.com,布布扣
<?xml version="1.0" encoding="utf-8"?>  
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:stretchColumns="0,1,2" >  //(此处表示第1,2,3列都拉宽屏幕)  
    <TableRow>  
        <TextView android:text="tmacsky1" />  
        <TextView android:text="tmacsky2" />  
        <TextView android:text="tmacsky3" />  
    </TableRow>  
    <TableRow>  
        <Button android:text="tmacsky1" />  
        <Button android:text="tmacsky2" />  
        <Button android:text="tmacsky3" />  
    </TableRow>  
    <TableRow>  
        <EditText />  
        <EditText />  
        <EditText />  
    </TableRow>  
</TableLayout> 
bubuko.com,布布扣

bubuko.com,布布扣

由此可以想象伸缩列其实就是用weight来封装的

3. android:collapseColumns缩进列

将第2个例子里的Android:stretchColumns缩进下加一行代码:

android:collapseColumns="0"

意思就是缩进第一列效果:

bubuko.com,布布扣

4,如果按钮里文字过多,则会出现下面这种情况

bubuko.com,布布扣

超出屏幕了;这个时候如果想让按钮里的文字换行不超出屏幕则可以:

 

在第二个例子的Android:stretchColumns添加一行代码:

android:shrinkColumns="2"

bubuko.com,布布扣

5.实现下面的效果

bubuko.com,布布扣

在第二个例子里的EditText代码改成这样:

bubuko.com,布布扣
<TableRow>
        <EditText android:layout_span="2"/>
        <EditText android:layout_column="2"/>
</TableRow>
bubuko.com,布布扣

Layout_span=2 伸展2

Layout_column=2  位置固定到第三列

UI篇--Android中TableLayout中的布局

原文:http://www.cnblogs.com/duanxz/p/3554658.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!