安卓根本布局(下)

[复制链接]
发表于 2026-2-14 02:37:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
TableLayout

常用属性形貌collapseColumns设置必要被潜伏的列的列号。shrinkColumns设置答应被伸缩的列的列号。stretchColumns设置答应被拉伸的列的列号。
  1. <TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
  2.     android:id="@+id/TableLayout"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="wrap_content"
  5.     android:collapseColumns="0,2"
  6.     android:shrinkColumns="3"
  7.     android:stretchColumns="1">
  8.     <TableRow>
  9.         <Button
  10.             android:layout_width="wrap_content"
  11.             android:layout_height="wrap_content"
  12.             android:text="one" />
  13.         <Button
  14.             android:layout_width="wrap_content"
  15.             android:layout_height="wrap_content"
  16.             android:text="two" />
  17.         <Button
  18.             android:layout_width="wrap_content"
  19.             android:layout_height="wrap_content"
  20.             android:text="three" />
  21.         <Button
  22.             android:layout_width="wrap_content"
  23.             android:layout_height="wrap_content"
  24.             android:text="four" />
  25.         <Button
  26.             android:layout_width="wrap_content"
  27.             android:layout_height="wrap_content"
  28.             android:text="five" />
  29.     </TableRow>
  30. </TableLayout>
复制代码

FrameLayout帧布局

  这个布局直接在屏幕上开辟出一块空缺的地区,当我们往内里添加控件的时间,会默认把他们放到这块地区的左上角。帧布局的巨细由控件中最大的子控件决定,如果控件的巨细一样大的话,那么同一时间就只能看到最上面的谁人组件,后续添加的控件会覆盖前一个。
  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools"
  3.     android:id="@+id/FrameLayout1"
  4.     android:layout_width="match_parent"
  5.     android:layout_height="match_parent"
  6.     tools:context=".FrameLayoutActivity">
  7.     <TextView
  8.         android:layout_width="200dp"
  9.         android:layout_height="200dp"
  10.         android:background="#FF6143" />
  11.     <TextView
  12.         android:layout_width="150dp"
  13.         android:layout_height="150dp"
  14.         android:background="#7BFE00" />
  15.     <TextView
  16.         android:layout_width="100dp"
  17.         android:layout_height="100dp"
  18.         android:background="#FFFF00" />
  19. </FrameLayout>
复制代码

GridLayout

  与表格布局类似,但是比表格布局机动。
常用属性形貌orientation设置分列方式。vertical:竖直(默认);horizontal:程度。layout_gravity设置对齐方式。rowCount设置行数。columnCount设置列数。layout_row设置第几行。layout_column设置第几列。layout_rowSpan设置高出几行。layout_columnSpan设置高出列数。
  1. <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools"
  3.     android:id="@+id/GridLayout1"
  4.     android:layout_width="wrap_content"
  5.     android:layout_height="wrap_content"
  6.     android:columnCount="5"
  7.     android:orientation="horizontal"
  8.     android:rowCount="5" >
  9.     <Button
  10.         android:layout_gravity="fill"
  11.         android:text="1"
  12.         android:layout_columnSpan="3"/>
  13.     <Button
  14.         android:layout_gravity="fill"
  15.         android:text="2"
  16.         android:layout_column="1"
  17.         android:layout_rowSpan="3"/>
  18.     <Button android:text="3" />
  19.     <Button
  20.         android:text="4"
  21.         android:layout_row="2"/>
  22.     <Button android:text="5" />
  23.     <Button android:text="6" />
  24.     <Button android:text="7" />
  25.     <Button android:text="8" />
  26.     <Button android:text="9" />
  27. </GridLayout>
复制代码

回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表