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个单元格 。
看代码
<TableLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center_vertical"android:stretchColumns="2"android:shrinkColumns="1"><TableRowandroid:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/button7"android:layout_width="139dp"android:layout_height="117dp"android:text="Button1"/><Buttonandroid:id="@+id/button6"android:layout_width="139dp"android:layout_height="117dp"android:text="Button2"/><Buttonandroid:id="@+id/button4"android:layout_width="139dp"android:layout_height="117dp"android:text="Button3"/></TableRow><TableRowandroid:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/button9"android:layout_width="139dp"android:layout_height="117dp"android:text="Button4"/><Buttonandroid:id="@+id/button8"android:layout_width="139dp"android:layout_height="117dp"android:text="Button5"/><Buttonandroid:id="@+id/button5"android:layout_width="139dp"android:layout_height="117dp"android:text="Button6"/></TableRow></TableLayout>
效果图

android相对布局详解 android框架布局文件详解

文章插图

android相对布局详解 android框架布局文件详解

文章插图
FrameLayout(帧布局)帧布局是最为简单的一种布局 。该布局为每个加入其中的控件创建一个空白区域 。称为一帧 。每个控件占据一帧 。采用帧布局时 。所有控件都默认显示在屏幕左上角 。并按照先后放入的顺序重叠摆放 。先放入的将会在最底层 。后放入的控件显示在最顶层 。帧布局使用于图层设计 。
属性
foreground :设置帧布局容器的前景图像
foregroundGravity :属性设置图像的显示位置
看代码
<FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:foreground="@mipmap/ic_launcher"android:foregroundGravity="bottom"><TextViewandroid:id="@+id/textView"android:layout_width="460dp"android:layout_height="336dp"android:background="@color/colorAccent"android:text="TextView"/><TextViewandroid:id="@+id/textView2"android:layout_width="332dp"android:layout_height="242dp"android:background="@color/colorPrimary"android:text="TextView"/></FrameLayout>
效果图
【android相对布局详解 android框架布局文件详解】
android相对布局详解 android框架布局文件详解

文章插图

android相对布局详解 android框架布局文件详解

文章插图

    推荐阅读