1. 河豚号 > 生活百科 >

android表格布局详解(android布局文件详解)

TableLayout(表格布局)

Android中的表格布局与HTML中的表格标签< table >< tr >< td >相似,通过使用表格的行与列来排列组件。如果一行上有多个组件的话,就要在TableLayout中添加一个TableRow的容器,把组件都丢到里面!一个Tablerow一行,有多少列则是看TableRow中的组件个数。

常用属性

android:collapseColumns:隐藏某一列

android:shrinkColumns:允许某一列收缩

android:stretchColumns:拉伸某一列

这三个属性的列号都是从0开始计算的,如shrinkColunmns = “3”,对应的是第四列,可以设置多个,用逗号隔开比如”0,3″,如果是所有列都生效,用”*”号即可。

android:layout_column=”3″:表示的就是跳过第三个,直接显示到第四个格子处,从1开始计算。

android:layout_span=”2″:表示合并2个单元格,也就说这个组件占2个单元格。

看代码

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_vertical"

android:stretchColumns="2"

android:shrinkColumns="1">

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/button7"

android:layout_width="139dp"

android:layout_height="117dp"

android:text="Button1" />

android:id="@+id/button6"

android:layout_width="139dp"

android:layout_height="117dp"

android:text="Button2" />

android:id="@+id/button4"

android:layout_width="139dp"

android:layout_height="117dp"

android:text="Button3" />

 

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/button9"

android:layout_width="139dp"

android:layout_height="117dp"

android:text="Button4" />

android:id="@+id/button8"

android:layout_width="139dp"

android:layout_height="117dp"

android:text="Button5" />

android:id="@+id/button5"

android:layout_width="139dp"

android:layout_height="117dp"

android:text="Button6" />

 

 

效果图

 

安卓界面布局之表格布局与帧布局

 

FrameLayout(帧布局)

帧布局是最为简单的一种布局,该布局为每个加入其中的控件创建一个空白区域,称为一帧,每个控件占据一帧。采用帧布局时,所有控件都默认显示在屏幕左上角,并按照先后放入的顺序重叠摆放,先放入的将会在最底层,后放入的控件显示在最顶层。帧布局使用于图层设计。

属性

foreground :设置帧布局容器的前景图像

foregroundGravity :属性设置图像的显示位置

看代码

android:layout_width="match_parent"

android:layout_height="match_parent"

android:foreground="@mipmap/ic_launcher"

android:foregroundGravity="bottom">

android:id="@+id/textView"

android:layout_width="460dp"

android:layout_height="336dp"

android:background="@color/colorAccent"

android:text="TextView" />

android:id="@+id/textView2"

android:layout_width="332dp"

android:layout_height="242dp"

android:background="@color/colorPrimary"

android:text="TextView" />

 

效果图

 

安卓界面布局之表格布局与帧布局

 

本文由网上采集发布,不代表我们立场,转载联系作者并注明出处:http://www.yujujie.cn/shbk/38254.html

联系我们

在线咨询:点击这里给我发消息

微信号:15705946153

工作日:9:30-18:30,节假日休息