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

1年前 (2024-04-20)

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" />效果图