网站内链建设锚文字建设,自建app平台,网站开发用什么技术做好,wordpress制作小说网站模板下载一、TableLayout的概述 表格布局是以行数和列数来确定位置进行排列。就像一间教室#xff0c;确定好行数与列数就能让同学有序入座。
注意#xff1a;我们需要先添加TableRow容器#xff0c;每添加一个就会多一行#xff0c;然后再往TableRow容器中添加其它组件。…一、TableLayout的概述 表格布局是以行数和列数来确定位置进行排列。就像一间教室确定好行数与列数就能让同学有序入座。
注意我们需要先添加TableRow容器每添加一个就会多一行然后再往TableRow容器中添加其它组件。
二、TableLayout的属性 2.1 、TableLayout(表格布局)的样式就像是一张表格。每个TableLayout都由多个TableRow组成每个TableRow就是一行有几个TableRow就有几行。TableLayout不会显示行号和列号也没有分割线其行数和列数都可以进行操作。 下面是 3 (行) x 3(列) 的TableLayout基本使用其xml布局文件table_layout.xml如下
?xml version1.0 encodingutf-8?
TableLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentTableRowButtonandroid:idid/button01android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮1 /Buttonandroid:idid/button02android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮2 /Buttonandroid:idid/button03android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮3 //TableRowTableRowButtonandroid:idid/button04android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮4 /Buttonandroid:idid/button05android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮5 /Buttonandroid:idid/button06android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮6 //TableRowTableRowButtonandroid:idid/button07android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮7 /Buttonandroid:idid/button08android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮8 /Buttonandroid:idid/button09android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮9 //TableRow
/TableLayout
效果图 2.2 、TableLayout的android:shrinkColumns属性当TableRow里边的空间布满布局的时候指定列自动延伸以填充可用部分。当TableRow里边的控件还没有布满布局时android:shrinkColumns不起作用。 下面的布局文件table_layout2.xml演示了android:shrinkColumns属性的使用
?xml version1.0 encodingutf-8?
TableLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:shrinkColumns2TableRowButtonandroid:idid/button01android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮1 /!-- android:text按钮1AAAAAAAAAAAAAAA --Buttonandroid:idid/button02android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮2 /!-- android:text按钮2AAAAAAAAAAAAAAA --Buttonandroid:idid/button03android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮3AAAAAAAAAAAAAAA //TableRowTableRowButtonandroid:idid/button04android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮4 /Buttonandroid:idid/button05android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮5 /Buttonandroid:idid/button06android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮6 //TableRowTableRowButtonandroid:idid/button07android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮7 /Buttonandroid:idid/button08android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮8 /Buttonandroid:idid/button09android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮9 //TableRow
/TableLayout
效果图 从上面的实际效果图片可以看到当TableLayout设置了android:shrinkColumns属性则在TableRow中的控件如果超长的话设置指定的列为可收缩的列。当可收缩的列太宽(内容过多)不会被挤出屏幕。当需要设置多列为可收缩时将列序号用逗号隔开。 2.3 、下面的布局文件table_layout3.xml演示了没有设置android:shrinkColumns属性则在TableRow中的控件超长也不会自动延伸以填充可用部分。
?xml version1.0 encodingutf-8?
TableLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentTableRowButtonandroid:idid/button01android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮1 /!-- android:text按钮1AAAAAAAAAAAAAAA --Buttonandroid:idid/button02android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮2AAAAAAAAAAAAAAA /!-- android:text按钮2 --Buttonandroid:idid/button03android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮3AAAAAAAAAAAAAAA //TableRowTableRowButtonandroid:idid/button04android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮4 /Buttonandroid:idid/button05android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮5 /Buttonandroid:idid/button06android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮6 //TableRowTableRowButtonandroid:idid/button07android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮7 /Buttonandroid:idid/button08android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮8 /Buttonandroid:idid/button09android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮9 //TableRow
/TableLayout
效果图 2.4、TableLayout的android:stretchColumns属性用于指定列对空白部分进行填充。 下面的布局文件table_layout4.xml演示了android:stretchColumns属性的使用
?xml version1.0 encodingutf-8?
TableLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:stretchColumns1TableRowButtonandroid:idid/button01android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮1/Buttonandroid:idid/button02android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮2/!-- android:text按钮2 --Buttonandroid:idid/button03android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮3//TableRowTableRowButtonandroid:idid/button04android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮4/Buttonandroid:idid/button05android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮5/Buttonandroid:idid/button06android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮6//TableRowTableRowButtonandroid:idid/button07android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮7/Buttonandroid:idid/button08android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮8/Buttonandroid:idid/button09android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮9//TableRow
/TableLayout
效果图 2.5、collapseColumns(隐藏列) 流程:在TableRow中定义5个按钮后,接着在最外层的TableLayout中添加以下属性: android:collapseColumns “0,2”就是隐藏第一与第三列,代码如下:
?xml version1.0 encodingutf-8?
TableLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:stretchColumns1TableLayoutandroid:idid/TableLayout2android:layout_widthfill_parentandroid:layout_heightwrap_contentandroid:collapseColumns0,2TableRowButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textone /Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:texttwo /Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textthree /Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textfour /Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textfive //TableRow/TableLayout
/TableLayout
效果图 三、使用实例
使用TableLayout来完成简单的登录界面,运行效果图如下:
流程解析:
1.调用gravity属性,设置为center_vertical,让布局里面的组件在竖直方向上居中 2.将TableLayout中的第一和第四列设置为可拉伸 3.在每个TableRow中添加两个TextView,用于拉伸填满该行,这样可以让表格水平居中 android:stretchColumns”0,3” 设置为0.3是为了让两边都充满,那么中间部分就可以居中了 TableLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:idid/TableLayout1android:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:background#FFFFFFandroid:gravitycenter_verticalandroid:stretchColumns0,3TableRowTextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text用户名: /EditTextandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:minWidth300dp //TableRowTableRowTextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text密 码: /EditTextandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:minWidth300dp //TableRowTableRowButtonandroid:layout_width0dpandroid:layout_heightwrap_contentandroid:layout_weight1android:text登陆 /Buttonandroid:layout_width0dpandroid:layout_heightwrap_contentandroid:layout_weight1android:text退出 //TableRow/TableLayout
效果图
文章转载自: http://www.morning.nhdmh.cn.gov.cn.nhdmh.cn http://www.morning.gjfym.cn.gov.cn.gjfym.cn http://www.morning.mfmrg.cn.gov.cn.mfmrg.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.gcftl.cn.gov.cn.gcftl.cn http://www.morning.gpsr.cn.gov.cn.gpsr.cn http://www.morning.xdpjf.cn.gov.cn.xdpjf.cn http://www.morning.frcxx.cn.gov.cn.frcxx.cn http://www.morning.bpncd.cn.gov.cn.bpncd.cn http://www.morning.bhznl.cn.gov.cn.bhznl.cn http://www.morning.qcnk.cn.gov.cn.qcnk.cn http://www.morning.fmswb.cn.gov.cn.fmswb.cn http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn http://www.morning.qtqjx.cn.gov.cn.qtqjx.cn http://www.morning.rsfp.cn.gov.cn.rsfp.cn http://www.morning.bwfsn.cn.gov.cn.bwfsn.cn http://www.morning.ldcsw.cn.gov.cn.ldcsw.cn http://www.morning.ltpph.cn.gov.cn.ltpph.cn http://www.morning.knscf.cn.gov.cn.knscf.cn http://www.morning.prgrh.cn.gov.cn.prgrh.cn http://www.morning.sgnxl.cn.gov.cn.sgnxl.cn http://www.morning.gswfs.cn.gov.cn.gswfs.cn http://www.morning.lbfgq.cn.gov.cn.lbfgq.cn http://www.morning.ktfnj.cn.gov.cn.ktfnj.cn http://www.morning.wttzp.cn.gov.cn.wttzp.cn http://www.morning.qdsmile.cn.gov.cn.qdsmile.cn http://www.morning.hwpcm.cn.gov.cn.hwpcm.cn http://www.morning.drytb.cn.gov.cn.drytb.cn http://www.morning.qtsks.cn.gov.cn.qtsks.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.csjps.cn.gov.cn.csjps.cn http://www.morning.jppb.cn.gov.cn.jppb.cn http://www.morning.kwqt.cn.gov.cn.kwqt.cn http://www.morning.jtmql.cn.gov.cn.jtmql.cn http://www.morning.nsfxt.cn.gov.cn.nsfxt.cn http://www.morning.tpqrc.cn.gov.cn.tpqrc.cn http://www.morning.fdrb.cn.gov.cn.fdrb.cn http://www.morning.nfpct.cn.gov.cn.nfpct.cn http://www.morning.xnlj.cn.gov.cn.xnlj.cn http://www.morning.gwwtm.cn.gov.cn.gwwtm.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn http://www.morning.hhxkl.cn.gov.cn.hhxkl.cn http://www.morning.ndxmn.cn.gov.cn.ndxmn.cn http://www.morning.pqwjh.cn.gov.cn.pqwjh.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.kyctc.cn.gov.cn.kyctc.cn http://www.morning.cjsnj.cn.gov.cn.cjsnj.cn http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn http://www.morning.junyaod.com.gov.cn.junyaod.com http://www.morning.lnnc.cn.gov.cn.lnnc.cn http://www.morning.dtnzk.cn.gov.cn.dtnzk.cn http://www.morning.burpgr.cn.gov.cn.burpgr.cn http://www.morning.fhhry.cn.gov.cn.fhhry.cn http://www.morning.wbfly.cn.gov.cn.wbfly.cn http://www.morning.dkfrd.cn.gov.cn.dkfrd.cn http://www.morning.bqmsm.cn.gov.cn.bqmsm.cn http://www.morning.gqtxz.cn.gov.cn.gqtxz.cn http://www.morning.jrhcp.cn.gov.cn.jrhcp.cn http://www.morning.qxljc.cn.gov.cn.qxljc.cn http://www.morning.fmrwl.cn.gov.cn.fmrwl.cn http://www.morning.lzbut.cn.gov.cn.lzbut.cn http://www.morning.qxxj.cn.gov.cn.qxxj.cn http://www.morning.fy974.cn.gov.cn.fy974.cn http://www.morning.xdlwm.cn.gov.cn.xdlwm.cn http://www.morning.ysmw.cn.gov.cn.ysmw.cn http://www.morning.cwlxs.cn.gov.cn.cwlxs.cn http://www.morning.bpncd.cn.gov.cn.bpncd.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.wyrkp.cn.gov.cn.wyrkp.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.dlwzm.cn.gov.cn.dlwzm.cn http://www.morning.hhfwj.cn.gov.cn.hhfwj.cn http://www.morning.frpfk.cn.gov.cn.frpfk.cn http://www.morning.jwdys.cn.gov.cn.jwdys.cn http://www.morning.yysqz.cn.gov.cn.yysqz.cn http://www.morning.rtbx.cn.gov.cn.rtbx.cn http://www.morning.xmttd.cn.gov.cn.xmttd.cn http://www.morning.jzdfc.cn.gov.cn.jzdfc.cn http://www.morning.cmfkp.cn.gov.cn.cmfkp.cn