大连市城乡建设厅网站,哈尔滨今天最新消息,全国公共资源交易平台官网,网页设计公司杭州表格布局#xff08;TableLayout#xff09;类以行和列的形式管理控件#xff0c;每一行为一个TableRow对象#xff0c;也可以作为一个View对象#xff1b;当为View对象时#xff0c;该View对象将跨越该行的所有列。在TableRow中可以添加子控件#xff0c;每添加一个子控… 表格布局TableLayout类以行和列的形式管理控件每一行为一个TableRow对象也可以作为一个View对象当为View对象时该View对象将跨越该行的所有列。在TableRow中可以添加子控件每添加一个子控件即为一列。 TableLayout布局中并不会为每一行、每一列或每个单元格绘制边框每一行可以有0个或多个单元格每个单元格为一个View对象。TableLayout中可以有空的单元格单元格也可以像HTML中那样跨越多个列。 在TableLayout布局中一个列的宽度由该列中最宽的那个单元格指定而表格的宽度是由父容器指定的。在TableLayout中可以为列设置三种属性
Shrinkable如果一个列被标识为Shrinkable则该列的宽度可以进行收缩以使表格能够适应其父容器的大小。Stretchable如果一个列被标识为Stretchable则该列的宽度可以进行拉伸以使填满表格中的空闲空间。Collapsed如果一个列被标识为Collapsed则该列会被隐藏。 注意一个列可以同时具有Shrinkable属性和Stretchable属性在这种情况下该列的宽度将任意拉伸或收缩以适应父容器。 TableLayout继承自LinearLayout类除了继承来自父类的属性和方法TableLayout类中还包含表格布局所特有的属性和方法如下表 属性名称 对应方法 描述android:collapseColumnssetColumnCollapsed(int,boolean)设置指定列号的列属性为Collapsedandroid:shrinkColumnssetShrinkAllColumns(boolean)设置指定列号的列属性为Shrinkableandroid:stretchColumnssetStretchAllColumns(boolean)设置指定列号的列属性为Stretchable 注意TableLayout中所谓的列序号是从0开始计算的。setShrinkAllColumns和setStretchAllColumns实现的功能是将表格中的所有列设置为Shrinkable或Stretchable。 下面来看一下效果 其中Main.xml代码如下 view plain copy?xml version1.0 encodingutf-8? LinearLayout android:idid/LinearLayout01 android:layout_widthfill_parent android:layout_heightfill_parent xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:backgrounddrawable/android android:gravitybottom !-- 第一行 -- TableLayout android:idid/TableLayout01 android:layout_widthfill_parent android:layout_heightwrap_content android:background#FFFFFF xmlns:androidhttp://schemas.android.com/apk/res/android TextView android:text我是单独的一行 android:idid/TextView01 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_centerInParenttrue android:background#fd8d8d android:textColor#000000 android:layout_margin4px /TextView /TableLayout TableLayout android:idid/TableLayout02 android:layout_widthfill_parent android:layout_heightwrap_content android:background#FFFFFF android:stretchColumns0 xmlns:androidhttp://schemas.android.com/apk/res/android !-- android:stretchColumns0 设置0号列为可伸展的列当有多个列可伸展时用逗号隔开 -- !-- 第二行 -- TableRow android:idid/TableRow01 android:layout_widthwrap_content android:layout_heightwrap_content !-- 第一列 -- TextView android:text我是被拉上的一列 android:idid/TextView02 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_centerInParenttrue android:background#9cfda3 android:textColor#000000 android:layout_margin4px /TextView !-- 第二列 -- TextView android:text我的内容少 android:idid/TextView03 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_centerInParenttrue android:background#8d9dfd android:textColor#000000 android:layout_margin4px /TextView /TableRow /TableLayout TableLayout android:idid/TableLayout03 android:layout_widthfill_parent android:layout_heightwrap_content android:background#FFFFFF android:collapseColumns1 android:shrinkColumns0 xmlns:androidhttp://schemas.android.com/apk/res/android !-- android:collapseColumns1 隐藏编号为1的列若有多个列要隐藏则用逗号隔开如0,2 -- !-- android:shrinkColumns0 设置0号列为可收缩的列可收缩的列会纵向扩展 若有多个列要收缩则用逗号隔开如0,2 -- !-- 第三行 -- TableRow android:idid/TableRow02 android:layout_widthwrap_content android:layout_heightwrap_content !-- 第一列 -- TextView android:text我的被收缩的一列被收缩的一列 android:idid/TextView04 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_centerInParenttrue android:background#9cfda3 android:textColor#000000 android:layout_margin4px /TextView !-- 第二列被设置为隐藏了 -- TextView android:text我的内容少 android:idid/TextView05 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_centerInParenttrue android:background#8d9dfd android:textColor#000000 android:layout_margin4px /TextView !-- 第三列 -- TextView android:text我的内容比较长比较长比较长 android:idid/TextView06 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_centerInParenttrue android:background#fd8d8d android:textColor#000000 android:layout_margin4px /TextView /TableRow /TableLayout /LinearLayout Activity代码为 view plain copypackage com.sunchis; import android.app.Activity; import android.os.Bundle; public class Android extends Activity { Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //设置屏幕 } }